home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / jikes-1.02 / src / ast.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-26  |  171.8 KB  |  5,795 lines

  1. // $Id: ast.h,v 1.13 1999/08/26 15:34:01 shields Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1998, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10.  
  11. #ifndef ast_INCLUDED
  12. #define ast_INCLUDED
  13.  
  14. #include "config.h"
  15. #include <assert.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include "stream.h"
  19. #include "symbol.h"
  20.  
  21. class Parser;
  22. class SemanticEnvironment;
  23.  
  24. //
  25. // Global function used when the space for a dynamic object is
  26. // preallocated,but we need to call a constructor to initialize the
  27. // space.
  28. //
  29. // inline static void *operator new(size_t, void *p) { return p; }
  30. //
  31.  
  32. //**********************************************************************************
  33. //
  34. // This file contains the definitions of the classes used to construct the
  35. // AST representation of a Java program.
  36. //
  37. // The node Ast is a base class of all other classes. (The name of the other classes
  38. // start with the prefix "Ast".) The nodes associated with executable statements
  39. // (e.g., AstIfStatement) are subclasses of AstStatement and nodes associated with
  40. // expressions (e.g., AstBinaryExpression) are subclasses of AstExpression.
  41. //
  42. // The information contained in the AST nodes is described by a grammar where
  43. // each rule consists of a left-hand side nonterminal followed by "-->" followed
  44. // by a right-hand side symbol or a sequence enclosed in the pair of symbols
  45. // "<" and ">". In defining the symbols, the following notation is used:
  46. //
  47. // Symbols that are capitalized (e.g., Type) are nonterminals. Symbols that are
  48. // in all upper case (e.g., PACKAGE) represent node kinds. Symbols that contain
  49. // the substring "_token" represents tokens in the source file. The suffix "_opt"
  50. // indicates that a symbol is optional. For example, if Super_opt appears in a
  51. // rule, it indicates that either Super or null can be expected. When a symbol
  52. // is plural (e.g., Modifiers), it indicates zero or more instances of such a
  53. // symbol (a list to be precise) can be expected. Thus, when "Modifiers" is
  54. // specified in the right-hand side of a rule either no Modifier or a sequence
  55. // of them may appear.
  56. //
  57. // Implementation Notes:
  58. //
  59. //    A complete AST tree for a Java program always contains an
  60. //    AstCompilationUnit root node. The kind of that node is
  61. //    Ast::EMPTY_COMPILATION for a tree with no type declaration,
  62. //    Ast::COMPILATION for a tree constructed from an otherwise valid program
  63. //    and Ast::BAD_COMPILATION for a tree constructed from an invalid program.
  64. //
  65. //    Since the AST is a tree data structure, each node contains a virtual
  66. //    destructor that can delete its subtrees. Therefore, a user can dispose of
  67. //    a whole ast tree (or subtree) by simply deleting the root node.
  68. //
  69. //    When the preprocessor variable TEST is defined the user may print out
  70. //    an AST tree to standard output by calling the virtual function "Print"
  71. //    for the root node of the tree.
  72. //
  73. //    DynamicArrays are used to implement lists. This representation has the
  74. //    advantage of being very flexible and easy to use. However, it may be slightly
  75. //    less time-efficient than a straightforward linked list. My guess is no more
  76. //    that 10% which justifies this use, but that should be checked at some point...
  77. //
  78. //**********************************************************************************
  79.  
  80. //
  81. // This is a complete list of all Ast nodes declared here to allow
  82. // forward references.
  83. //
  84. class Ast;
  85. class AstListNode;
  86. class AstStatement;
  87. class AstExpression;
  88. class AstPrimitiveType;
  89. class AstArrayType;
  90. class AstSimpleName;
  91. class AstPackageDeclaration;
  92. class AstImportDeclaration;
  93. class AstCompilationUnit;
  94. class AstModifier;
  95. class AstEmptyDeclaration;
  96. class AstClassDeclaration;
  97. class AstClassBody;
  98. class AstArrayInitializer;
  99. class AstBrackets;
  100. class AstVariableDeclaratorId;
  101. class AstVariableDeclarator;
  102. class AstFieldDeclaration;
  103. class AstFormalParameter;
  104. class AstMethodDeclarator;
  105. class AstMethodDeclaration;
  106. class AstStaticInitializer;
  107. class AstThisCall;
  108. class AstSuperCall;
  109. class AstConstructorBlock;
  110. class AstConstructorDeclaration;
  111. class AstInterfaceDeclaration;
  112. class AstBlock;
  113. class AstLocalVariableDeclarationStatement;
  114. class AstIfStatement;
  115. class AstEmptyStatement;
  116. class AstExpressionStatement;
  117. class AstCaseLabel;
  118. class AstDefaultLabel;
  119. class AstSwitchBlockStatement;
  120. class AstSwitchStatement;
  121. class AstWhileStatement;
  122. class AstDoStatement;
  123. class AstForStatement;
  124. class AstBreakStatement;
  125. class AstContinueStatement;
  126. class AstReturnStatement;
  127. class AstThrowStatement;
  128. class AstSynchronizedStatement;
  129. class AstCatchClause;
  130. class AstFinallyClause;
  131. class AstTryStatement;
  132. class AstIntegerLiteral;
  133. class AstLongLiteral;
  134. class AstFloatingPointLiteral;
  135. class AstDoubleLiteral;
  136. class AstTrueLiteral;
  137. class AstFalseLiteral;
  138. class AstStringLiteral;
  139. class AstCharacterLiteral;
  140. class AstNullLiteral;
  141. class AstThisExpression;
  142. class AstSuperExpression;
  143. class AstParenthesizedExpression;
  144. class AstClassInstanceCreationExpression;
  145. class AstDimExpr;
  146. class AstArrayCreationExpression;
  147. class AstFieldAccess;
  148. class AstMethodInvocation;
  149. class AstArrayAccess;
  150. class AstPostUnaryExpression;
  151. class AstPreUnaryExpression;
  152. class AstCastExpression;
  153. class AstBinaryExpression;
  154. class AstTypeExpression;
  155. class AstConditionalExpression;
  156. class AstAssignmentExpression;
  157.  
  158. class CaseElement;
  159.  
  160. class StoragePool;
  161.  
  162. //
  163. // The Ast base node.
  164. //
  165. class Ast
  166. {
  167. public:
  168.     //
  169.     // These tags are used to identify nodes that can represent more than
  170.     // one kind of objects.
  171.     //
  172.     enum AstTag
  173.     {
  174.         NO_TAG,
  175.         PRIMITIVE_TYPE,
  176.         STATEMENT,
  177.         EXPRESSION,
  178.         MODIFIER,
  179.         STATIC_FIELD,
  180.         UNPARSED,
  181.  
  182.         _num_tags = MODIFIER
  183.     };
  184.  
  185.     //
  186.     // These are the different kinds for the Ast objects.
  187.     //
  188.     enum AstKind
  189.     {
  190.         AST,
  191.         IDENTIFIER,
  192.         DOT,
  193.         INTEGER_LITERAL,
  194.         LONG_LITERAL,
  195.         FLOATING_POINT_LITERAL,
  196.         DOUBLE_LITERAL,
  197.         TRUE_LITERAL,
  198.         FALSE_LITERAL,
  199.         STRING_LITERAL,
  200.         CHARACTER_LITERAL,
  201.         NULL_LITERAL,
  202.         ARRAY_ACCESS,
  203.         CALL,
  204.         THIS_EXPRESSION,
  205.         SUPER_EXPRESSION,
  206.         PARENTHESIZED_EXPRESSION,
  207.         CLASS_CREATION,
  208.         ARRAY_CREATION,
  209.         POST_UNARY,
  210.         PRE_UNARY,
  211.         CAST,
  212.         CHECK_AND_CAST,
  213.         BINARY,
  214.         TYPE,
  215.         CONDITIONAL,
  216.         ASSIGNMENT,
  217.  
  218.         _num_expression_kinds,
  219.  
  220.         DIM = _num_expression_kinds,
  221.         LIST_NODE,
  222.         INT,
  223.         DOUBLE,
  224.         CHAR,
  225.         LONG,
  226.         FLOAT,
  227.         BYTE,
  228.         SHORT,
  229.         BOOLEAN,
  230.         VOID_TYPE,
  231.         ARRAY,
  232.         COMPILATION,
  233.         BAD_COMPILATION,
  234.         EMPTY_COMPILATION,
  235.         PACKAGE_COMPONENT,
  236.         PACKAGE_NAME,
  237.         PACKAGE,
  238.         IMPORT,
  239.         EMPTY_DECLARATION,
  240.         CLASS,
  241.         CLASS_BODY,
  242.         PUBLIC,
  243.         PROTECTED,
  244.         PRIVATE,
  245.         STATIC,
  246.         ABSTRACT,
  247.         FINAL,
  248.         NATIVE,
  249.         STRICTFP,
  250.         SYNCHRONIZED,
  251.         TRANSIENT,
  252.         VOLATILE,
  253.         FIELD,
  254.         VARIABLE_DECLARATOR,
  255.         VARIABLE_DECLARATOR_NAME,
  256.         BRACKETS,
  257.         METHOD,
  258.         METHOD_DECLARATOR,
  259.         PARAMETER,
  260.         CONSTRUCTOR,
  261.         INTERFACE,
  262.         ARRAY_INITIALIZER,
  263.         STATIC_INITIALIZER,
  264.         THIS_CALL,
  265.         SUPER_CALL,
  266.         BLOCK,
  267.         CONSTRUCTOR_BLOCK,
  268.         LOCAL_VARIABLE_DECLARATION,
  269.         IF,
  270.         EMPTY_STATEMENT,
  271.         EXPRESSION_STATEMENT,
  272.         SWITCH,
  273.         SWITCH_BLOCK,
  274.         CASE,
  275.         DEFAULT,
  276.         WHILE,
  277.         DO,
  278.         FOR,
  279.         BREAK,
  280.         CONTINUE,
  281.         RETURN,
  282.         THROW,
  283.         SYNCHRONIZED_STATEMENT,
  284.         TRY,
  285.         CATCH,
  286.         FINALLY,
  287.  
  288.         _num_kinds
  289.     };
  290.  
  291. #ifdef TEST
  292.     typedef AstKind Kind;
  293.     typedef AstTag  Tag;
  294. #else
  295.     typedef unsigned short Kind;
  296.     typedef unsigned char  Tag;
  297. #endif
  298.  
  299.     Kind  kind;      // every node has a unique kind...
  300.     Tag   class_tag; // Some subsets of nodes are grouped together to form a class of nodes.
  301.     bool  generated; // "generated" is a boolean value that indicates whether or not a node
  302.                      // is associated with a construct in a source file or that is was generated
  303.                      // by the compiler. See functions "gen_ ..." and "new_ ..." below.
  304.  
  305. #ifdef TEST
  306.     unsigned id;
  307.     static unsigned count;
  308.  
  309.     Ast() : id(++count)
  310.     {}
  311. #endif
  312.  
  313.     virtual ~Ast();
  314.  
  315. #ifdef TEST
  316.     virtual void Print(LexStream &);
  317. #endif
  318.  
  319.     //
  320.     // Given an Ast tree, check whether or not it is a Name - simple or qualified.
  321.     //
  322.     bool IsName();
  323.     bool IsSimpleNameOrFieldAccess();
  324.     bool IsSuperExpression();
  325.     bool IsLeftHandSide();
  326.     bool IsGenerated();
  327.  
  328.     //
  329.     // The Conversion functions below are provided as a convenient way to
  330.     // cast a generic Ast node into a specific node. Note that if one knows
  331.     // the type of a node for sure, it is more efficient to use a specific
  332.     // cast expression. For example, if one knows that a "Ast *p" pointer
  333.     // dereferences a FieldDeclaration then a cast expression should be
  334.     // used to cast p, as follows:
  335.     //
  336.     //       AstFieldDeclaration *fp = (FieldDeclaration *) p;
  337.     //
  338.     // However, if p points to a ClassBodyDeclaration which may be
  339.     // either a FieldDeclaration, MethodDeclaration, ConstructorDeclaration,
  340.     // StaticInitializer, ClassDeclaration, InterfaceDeclaration or a block
  341.     // then the following sequence of code may be used:
  342.     //
  343.     //    AstFieldDeclaration       *fp;
  344.     //    AstMethodDeclaration      *mp;
  345.     //    AstConstructorDeclaration *cp;
  346.     //    AstStaticInitializer      *sp;
  347.     //    AstClassDeclaration       *Cp; // 1.1 only
  348.     //    AstInterfaceDeclaration   *Ip; // 1.1 only
  349.     //    AstBlock                  *Bp; // 1.1 only
  350.     //
  351.     //    if (fp = p -> FieldDeclaration())
  352.     //        ...
  353.     //    else if (mp = p -> MethodDeclaration())
  354.     //        ...
  355.     //    else if (cp = p -> ConstructorDeclaration())
  356.     //        ...
  357.     //    else if (sp = p -> StaticInitializer())
  358.     //        ...
  359.     //    else if (Cp = p -> ClassDeclaration())
  360.     //        ...
  361.     //    else if (Ip = p -> InterfaceDeclaration())
  362.     //        ...
  363.     //    else if (Bp = p -> Block())
  364.     //        ...
  365.     //
  366.  
  367.     //
  368.     // These cast functions are used for classes that represent more than
  369.     // one kind of nodes.
  370.     //
  371.     AstStatement *StatementCast()                        { return (AstStatement *) (class_tag == STATEMENT ? this : NULL); }
  372.     AstExpression *ExpressionCast()                      { return (AstExpression *) (class_tag == EXPRESSION ? this : NULL); }
  373.     AstPrimitiveType *PrimitiveTypeCast()                { return (AstPrimitiveType *) (class_tag == PRIMITIVE_TYPE ? this : NULL); }
  374.     AstModifier *ModifierCast()                          { return (AstModifier *) (class_tag == MODIFIER ? this : NULL); }
  375.     AstFieldDeclaration *StaticFieldCast()               { return (AstFieldDeclaration *) (class_tag == STATIC_FIELD ? this : NULL); }
  376.     AstClassBody *UnparsedClassBodyCast()                { return (AstClassBody *) (class_tag == UNPARSED ? this : NULL); }
  377.     AstInterfaceDeclaration *UnparsedInterfaceBodyCast() { return (AstInterfaceDeclaration *) (class_tag == UNPARSED ? this : NULL); }
  378.  
  379.     //
  380.     // These cast functions are used for classes that represent exactly
  381.     // one kind of node.
  382.     //
  383.     AstListNode *ListNodeCast() { return (AstListNode *) (kind == LIST_NODE ? this : NULL); }
  384.     AstArrayType *ArrayTypeCast() { return (AstArrayType *) (kind == ARRAY ? this : NULL); }
  385.     AstSimpleName *SimpleNameCast() { return (AstSimpleName *) (kind == IDENTIFIER ? this : NULL); }
  386.     AstPackageDeclaration *PackageDeclarationCast() { return (AstPackageDeclaration *) (kind == PACKAGE ? this : NULL); }
  387.     AstImportDeclaration *ImportDeclarationCast() { return (AstImportDeclaration *) (kind == IMPORT ? this : NULL); }
  388.     AstCompilationUnit *CompilationUnitCast()
  389.       { return (AstCompilationUnit *) (kind == COMPILATION || kind == BAD_COMPILATION || kind == EMPTY_COMPILATION ? this : NULL); }
  390.     AstCompilationUnit *BadCompilationUnitCast() { return (AstCompilationUnit *) (kind == BAD_COMPILATION ? this : NULL); }
  391.     AstCompilationUnit *EmptyCompilationUnitCast() { return (AstCompilationUnit *) (kind == EMPTY_COMPILATION ? this : NULL); }
  392.     AstEmptyDeclaration *EmptyDeclarationCast() { return (AstEmptyDeclaration *) (kind == EMPTY_DECLARATION ? this : NULL); }
  393.     AstClassDeclaration *ClassDeclarationCast() { return (AstClassDeclaration *) (kind == CLASS ? this : NULL); }
  394.     AstArrayInitializer *ArrayInitializerCast() { return (AstArrayInitializer *) (kind == ARRAY_INITIALIZER ? this : NULL); }
  395.     AstBrackets *BracketsCast() { return (AstBrackets *) (kind == BRACKETS ? this : NULL); }
  396.     AstVariableDeclaratorId *VariableDeclaratorIdCast()
  397.         { return (AstVariableDeclaratorId *) (kind == VARIABLE_DECLARATOR_NAME ? this : NULL); }
  398.     AstVariableDeclarator *VariableDeclaratorCast()
  399.         { return (AstVariableDeclarator *) (kind == VARIABLE_DECLARATOR ? this : NULL); }
  400.     AstFieldDeclaration *FieldDeclarationCast() { return (AstFieldDeclaration *) (kind == FIELD ? this : NULL); }
  401.     AstFormalParameter *FormalParameterCast() { return (AstFormalParameter *) (kind == PARAMETER ? this : NULL); }
  402.     AstMethodDeclarator *MethodDeclaratorCast() { return (AstMethodDeclarator *) (kind == METHOD_DECLARATOR ? this : NULL); }
  403.     AstMethodDeclaration *MethodDeclarationCast() { return (AstMethodDeclaration *) (kind == METHOD ? this : NULL); }
  404.     AstStaticInitializer *StaticInitializerCast()
  405.         { return (AstStaticInitializer *) (kind == STATIC_INITIALIZER ? this : NULL); }
  406.     AstThisCall *ThisCallCast() { return (AstThisCall *) (kind == THIS_CALL ? this : NULL); }
  407.     AstSuperCall *SuperCallCast() { return (AstSuperCall *) (kind == SUPER_CALL ? this : NULL); }
  408.     AstConstructorBlock *ConstructorBlockCast()
  409.         { return (AstConstructorBlock *) (kind == CONSTRUCTOR_BLOCK ? this : NULL); }
  410.     AstConstructorDeclaration *ConstructorDeclarationCast()
  411.         { return (AstConstructorDeclaration *) (kind == CONSTRUCTOR ? this : NULL); }
  412.     AstInterfaceDeclaration *InterfaceDeclarationCast()
  413.         { return (AstInterfaceDeclaration *) (kind == INTERFACE ? this : NULL); }
  414.     AstBlock *BlockCast() { return (AstBlock *) (kind == BLOCK ? this : NULL); }
  415.     AstLocalVariableDeclarationStatement *LocalVariableDeclarationStatementCast()
  416.         { return (AstLocalVariableDeclarationStatement *) (kind == LOCAL_VARIABLE_DECLARATION ? this : NULL); }
  417.     AstIfStatement *IfStatementCast() { return (AstIfStatement *) (kind == IF ? this : NULL); }
  418.     AstEmptyStatement *EmptyStatementCast() { return (AstEmptyStatement *) (kind == EMPTY_STATEMENT ? this : NULL); }
  419.     AstExpressionStatement *ExpressionStatementCast()
  420.         { return (AstExpressionStatement *) (kind == EXPRESSION_STATEMENT ? this : NULL); }
  421.     AstCaseLabel *CaseLabelCast() { return (AstCaseLabel *) (kind == CASE ? this : NULL); }
  422.     AstDefaultLabel *DefaultLabelCast() { return (AstDefaultLabel *) (kind == DEFAULT ? this : NULL); }
  423.     AstSwitchBlockStatement *SwitchBlockStatementCast()
  424.         { return (AstSwitchBlockStatement *) (kind == SWITCH_BLOCK ? this : NULL); }
  425.     AstSwitchStatement *SwitchStatementCast() { return (AstSwitchStatement *) (kind == SWITCH ? this : NULL); }
  426.     AstWhileStatement *WhileStatementCast() { return (AstWhileStatement *) (kind == WHILE ? this : NULL); }
  427.     AstDoStatement *DoStatementCast() { return (AstDoStatement *) (kind == DO ? this : NULL); }
  428.     AstForStatement *ForStatementCast() { return (AstForStatement *) (kind == FOR ? this : NULL); }
  429.     AstBreakStatement *BreakStatementCast() { return (AstBreakStatement *) (kind == BREAK ? this : NULL); }
  430.     AstContinueStatement *ContinueStatementCast() { return (AstContinueStatement *) (kind == CONTINUE ? this : NULL); }
  431.     AstReturnStatement *ReturnStatementCast() { return (AstReturnStatement *) (kind == RETURN ? this : NULL); }
  432.     AstThrowStatement *ThrowStatementCast() { return (AstThrowStatement *) (kind == THROW ? this : NULL); }
  433.     AstSynchronizedStatement *SynchronizedStatementCast()
  434.         { return (AstSynchronizedStatement *) (kind == SYNCHRONIZED_STATEMENT ? this : NULL); }
  435.     AstCatchClause *CatchClauseCast() { return (AstCatchClause *) (kind == CATCH ? this : NULL); }
  436.     AstFinallyClause *FinallyClauseCast() { return (AstFinallyClause *) (kind == FINALLY ? this : NULL); }
  437.     AstTryStatement *TryStatementCast() { return (AstTryStatement *) (kind == TRY ? this : NULL); }
  438.     AstIntegerLiteral *IntegerLiteralCast() { return (AstIntegerLiteral *) (kind == INTEGER_LITERAL ? this : NULL); }
  439.     AstLongLiteral *LongLiteralCast() { return (AstLongLiteral *) (kind == LONG_LITERAL ? this : NULL); }
  440.     AstFloatingPointLiteral *FloatingPointLiteralCast()
  441.         { return (AstFloatingPointLiteral *) (kind == FLOATING_POINT_LITERAL ? this : NULL); }
  442.     AstDoubleLiteral *DoubleLiteralCast() { return (AstDoubleLiteral *) (kind == DOUBLE_LITERAL ? this : NULL); }
  443.     AstTrueLiteral *TrueLiteralCast() { return (AstTrueLiteral *) (kind == TRUE_LITERAL ? this : NULL); }
  444.     AstFalseLiteral *FalseLiteralCast() { return (AstFalseLiteral *) (kind == FALSE_LITERAL ? this : NULL); }
  445.     AstStringLiteral *StringLiteralCast() { return (AstStringLiteral *) (kind == STRING_LITERAL ? this : NULL); }
  446.     AstCharacterLiteral *CharacterLiteralCast() { return (AstCharacterLiteral *) (kind == CHARACTER_LITERAL ? this : NULL); }
  447.     AstNullLiteral *NullLiteralCast() { return (AstNullLiteral *) (kind == NULL_LITERAL ? this : NULL); }
  448.     AstThisExpression *ThisExpressionCast() { return (AstThisExpression *) (kind == THIS_EXPRESSION ? this : NULL); }
  449.     AstSuperExpression *SuperExpressionCast() { return (AstSuperExpression *) (kind == SUPER_EXPRESSION ? this : NULL); }
  450.     AstParenthesizedExpression *ParenthesizedExpressionCast()
  451.         { return (AstParenthesizedExpression *) (kind == PARENTHESIZED_EXPRESSION ? this : NULL); }
  452.     AstClassInstanceCreationExpression *ClassInstanceCreationExpressionCast()
  453.         { return (AstClassInstanceCreationExpression *) (kind == CLASS_CREATION ? this : NULL); }
  454.     AstDimExpr *DimExprCast() { return (AstDimExpr *) (kind == DIM ? this : NULL); }
  455.     AstArrayCreationExpression *ArrayCreationExpressionCast()
  456.         { return (AstArrayCreationExpression *) (kind == ARRAY_CREATION ? this : NULL); }
  457.     AstFieldAccess *FieldAccessCast() { return (AstFieldAccess *) (kind == DOT ? this : NULL); }
  458.     AstMethodInvocation *MethodInvocationCast() { return (AstMethodInvocation *) (kind == CALL ? this : NULL); }
  459.     AstArrayAccess *ArrayAccessCast() { return (AstArrayAccess *) (kind == ARRAY_ACCESS ? this : NULL); }
  460.     AstPostUnaryExpression *PostUnaryExpressionCast()
  461.         { return (AstPostUnaryExpression *) (kind == POST_UNARY ? this : NULL); }
  462.     AstPreUnaryExpression *PreUnaryExpressionCast()
  463.         { return (AstPreUnaryExpression *) (kind == PRE_UNARY ? this : NULL); }
  464.     AstCastExpression *CastExpressionCast() { return (AstCastExpression *) (kind == CAST || kind == CHECK_AND_CAST ? this : NULL); }
  465.     AstBinaryExpression *BinaryExpressionCast() { return (AstBinaryExpression *) (kind == BINARY ? this : NULL); }
  466.     AstTypeExpression *TypeExpressionCast() { return (AstTypeExpression *) (kind == TYPE ? this : NULL); }
  467.     AstConditionalExpression *ConditionalExpressionCast()
  468.         { return (AstConditionalExpression *) (kind == CONDITIONAL ? this : NULL); }
  469.     AstAssignmentExpression *AssignmentExpressionCast()
  470.         { return (AstAssignmentExpression *) (kind == ASSIGNMENT ? this : NULL); }
  471.  
  472.     virtual Ast *Clone(StoragePool *);
  473.  
  474.     virtual LexStream::TokenIndex LeftToken()  { return 0; }
  475.     virtual LexStream::TokenIndex RightToken() { return 0; }
  476. };
  477.  
  478.  
  479. //
  480. // This AstArray template class can be used to construct a dynamic
  481. // array of arbitrary objects. The space for the array is allocated in
  482. // blocks of size 2**LOG_BLKSIZE. In declaring a Ast array the user
  483. // may specify a value for LOG_BLKSIZE which by default is 6. Also,
  484. // as the array is implemented using a base+offset strategy, the user
  485. // may also specify the number of "slots" to add to the base when the
  486. // current base runs out of space. Each slot points to a block.
  487. //
  488. template <class T>
  489. class AstArray
  490. {
  491.     T **base;
  492.     int base_size,
  493.         top,
  494.         size;
  495.     StoragePool *pool;
  496.     unsigned short log_blksize,
  497.                    base_increment;
  498.  
  499.     inline size_t Blksize() { return (1 << log_blksize); }
  500.  
  501.     //
  502.     // Allocate another block of storage for the Ast array.
  503.     //
  504.     void AllocateMoreSpace();
  505.  
  506. public:
  507.  
  508.     //
  509.     // This function is used to reset the size of a Ast array without
  510.     // allocating or deallocting space. It may be invoked with an integer
  511.     // argument n which indicates the new size or with no argument which
  512.     // indicates that the size should be reset to 0.
  513.     //
  514.     void Reset(const int n = 0)
  515.     {
  516.         if (n < 0 || n > size)
  517.             assert(false);
  518.         top = n;
  519.     }
  520.  
  521.     //
  522.     // Return length of the Ast array.
  523.     //
  524.     int Length() { return top; }
  525.  
  526.     //
  527.     // Return a reference to the ith element of the Ast array.
  528.     //
  529.     // Note that no check is made here to ensure that 0 <= i < top.
  530.     // Such a check might be useful for debugging and a range exception
  531.     // should be thrown if it yields true.
  532.     //
  533.     T& operator[](const int i) { return base[i >> log_blksize][i]; }
  534.  
  535.     //
  536.     // Add an element to the Ast array and return the top index.
  537.     //
  538.     int NextIndex()
  539.     {
  540.         int i = top++;
  541.         if (i == size)
  542.             AllocateMoreSpace();
  543.         return i;
  544.     }
  545.  
  546.     //
  547.     // Add an element to the Ast array and return a reference to
  548.     // that new element.
  549.     //
  550.     T& Next() { int i = NextIndex(); return base[i >> log_blksize][i]; }
  551.  
  552.     //
  553.     // Constructor of a ast array.
  554.     //
  555.     AstArray(StoragePool *, unsigned);
  556.  
  557.     //
  558.     // Destructor of an Ast array.
  559.     //
  560.     ~AstArray() { assert(false); }
  561. };
  562.  
  563.  
  564. //
  565. // The Ast base node.
  566. //
  567. class AstListNode : public Ast
  568. {
  569. public:
  570.     AstListNode *next;
  571.     Ast *element;
  572.     unsigned index;
  573.  
  574.     AstListNode()
  575.     {
  576.         Ast::kind = Ast::LIST_NODE;
  577.         Ast::class_tag = Ast::NO_TAG;
  578.         Ast::generated = 0;
  579. #ifdef TEST
  580.         --count; // don't count these nodes
  581. #endif
  582.     }
  583.  
  584.     ~AstListNode() {}
  585. };
  586.  
  587.  
  588. class AstStatement : public Ast
  589. {
  590. public:
  591.     bool is_reachable,
  592.          can_complete_normally;
  593.  
  594.     //
  595.     // Note that for efficiency reasons AstStatement does not have a constructor.
  596.     // Therefore, subclasses that are derived from AstStatement are expected to
  597.     // initialize the fields is_reachable and can_complete_normally appropriately.
  598.     //
  599.  
  600.     virtual ~AstStatement();
  601.  
  602.     virtual Ast *Clone(StoragePool *) { return (Ast *) NULL; }
  603.  
  604.     virtual LexStream::TokenIndex LeftToken()  { return 0; }
  605.     virtual LexStream::TokenIndex RightToken() { return 0; }
  606. };
  607.  
  608.  
  609. class AstExpression : public Ast
  610. {
  611. public:
  612.     LiteralValue *value;
  613.     Symbol *symbol;
  614.  
  615.     //
  616.     // Note that for efficiency reasons AstExpression does not have a constructor.
  617.     // However, subclasses that are derived from AstExpression are expected to
  618.     // initialize the fields value and symbol to NULL as indicated below:
  619.     //
  620.     // AstExpression() : value(NULL),
  621.     //                   symbol(NULL)
  622.     // {}
  623.     //
  624.  
  625.     virtual ~AstExpression();
  626.  
  627.     bool IsConstant() { return (value != NULL); }
  628.  
  629.     TypeSymbol *Type()
  630.     {
  631.         return (TypeSymbol *)
  632.                (symbol ? (symbol -> Kind() == Symbol::TYPE
  633.                                   ? (TypeSymbol *) symbol
  634.                                   : (symbol -> Kind() == Symbol::VARIABLE
  635.                                              ? ((VariableSymbol *) symbol) -> Type()
  636.                                              : (symbol -> Kind() == Symbol::METHOD
  637.                                                         ? ((MethodSymbol *) symbol) -> Type()
  638.                                                         : NULL)))
  639.                        : NULL);
  640.     }
  641.  
  642.     virtual Ast *Clone(StoragePool *) { return (Ast *) NULL; }
  643.  
  644.     virtual LexStream::TokenIndex LeftToken()  { return 0; }
  645.     virtual LexStream::TokenIndex RightToken() { return 0; }
  646. };
  647.  
  648.  
  649. //
  650. // Block --> <BLOCK, {_token, BlockStatements, }_token>
  651. //
  652. // BlockStatement --> LocalVariableDeclarationStatement
  653. //                  | Statement
  654. //
  655. class AstBlock : public AstStatement
  656. {
  657. private:
  658.  
  659.     StoragePool *pool;
  660.     AstArray<LexStream::TokenIndex> *labels;
  661.     AstArray<Ast *> *block_statements;
  662.  
  663. public:
  664.     BlockSymbol *block_symbol;
  665.  
  666.     int nesting_level;
  667.     LexStream::TokenIndex left_brace_token;
  668.     LexStream::TokenIndex right_brace_token;
  669.  
  670.     AstBlock(StoragePool *pool_) : pool(pool_),
  671.                                    labels(NULL),
  672.                                    block_statements(NULL),
  673.                                    block_symbol(NULL),
  674.                                    nesting_level(0)
  675.     {
  676.         Ast::kind = Ast::BLOCK;
  677.         Ast::class_tag = Ast::STATEMENT;
  678.         Ast::generated = 0;
  679.         AstStatement::is_reachable = false;
  680.         AstStatement::can_complete_normally = false;
  681.  
  682.         return;
  683.     }
  684.  
  685.     virtual ~AstBlock();
  686.  
  687.     inline Ast *&Statement(int i) { return (*block_statements)[i]; }
  688.     inline int NumStatements() { return (block_statements ? block_statements -> Length() : 0); }
  689.     inline void AllocateBlockStatements(int estimate = 0);
  690.     inline void AddStatement(Ast *);
  691.  
  692.     inline LexStream::TokenIndex &Label(int i) { return (*labels)[i]; }
  693.     inline int NumLabels() { return (labels ? labels -> Length() : 0); }
  694.     inline void AllocateLabels(int estimate = 4);
  695.     inline void AddLabel(LexStream::TokenIndex);
  696.  
  697. #ifdef TEST
  698.     virtual void Print(LexStream &);
  699. #endif
  700.  
  701.     virtual Ast *Clone(StoragePool *);
  702.  
  703.     virtual LexStream::TokenIndex LeftToken()  { return left_brace_token; }
  704.     virtual LexStream::TokenIndex RightToken() { return right_brace_token; }
  705. };
  706.  
  707. //
  708. // Type --> PrimitiveType
  709. //        | ReferenceType
  710. //
  711. // PrimitiveType --> <PrimitiveKind, PrimitiveName>
  712. //
  713. // PrimitiveKind --> BYTE | SHORT | INT | LONG | CHAR | FLOAT | DOUBLE | BOOLEAN | VOID
  714. //
  715. // PrimitiveName --> byte_token | short_token | int_token | long_token |
  716. //                   char_token | float_token | double_token | boolean_token | void_token
  717. //
  718. class AstPrimitiveType : public Ast
  719. {
  720. public:
  721.     LexStream::TokenIndex primitive_kind_token;
  722.  
  723.     AstPrimitiveType(Ast::Kind kind_, LexStream::TokenIndex token_) : primitive_kind_token(token_)
  724.     {
  725.         Ast::kind = kind_;
  726.         Ast::class_tag = Ast::PRIMITIVE_TYPE;
  727.         Ast::generated = 0;
  728.     }
  729.  
  730.     virtual ~AstPrimitiveType();
  731.  
  732. #ifdef TEST
  733.     virtual void Print(LexStream &);
  734. #endif
  735.  
  736.     virtual Ast *Clone(StoragePool *);
  737.  
  738.     virtual LexStream::TokenIndex LeftToken()  { return primitive_kind_token; }
  739.     virtual LexStream::TokenIndex RightToken() { return primitive_kind_token; }
  740. };
  741.  
  742.  
  743. //
  744. // Brackets --> <BRACKETS, [_token, ]_token>
  745. //
  746. class AstBrackets : public Ast
  747. {
  748. public:
  749.     LexStream::TokenIndex left_bracket_token;
  750.     LexStream::TokenIndex right_bracket_token;
  751.  
  752.     AstBrackets(LexStream::TokenIndex left_, LexStream::TokenIndex right_) : left_bracket_token(left_),
  753.                                                                              right_bracket_token(right_)
  754.     {
  755.         Ast::kind = Ast::BRACKETS;
  756.         Ast::class_tag = Ast::NO_TAG;
  757.         Ast::generated = 0;
  758.     }
  759.  
  760.     virtual ~AstBrackets();
  761.  
  762. #ifdef TEST
  763.     virtual void Print(LexStream &);
  764. #endif
  765.  
  766.     virtual Ast *Clone(StoragePool *);
  767.  
  768.     virtual LexStream::TokenIndex LeftToken()  { return left_bracket_token; }
  769.     virtual LexStream::TokenIndex RightToken() { return right_bracket_token; }
  770. };
  771.  
  772.  
  773. //
  774. // ReferenceType --> ClassType
  775. //                 | ArrayType
  776. //
  777. // ClassType --> Name
  778. //
  779. // ArrayType --> <ARRAY, ArrayKind, [_token, ]_token>
  780. //
  781. // ArrayKind --> PrimitiveType
  782. //             | Name
  783. //             | ArrayType
  784. //
  785. class AstArrayType : public Ast
  786. {
  787. private:
  788.  
  789.     StoragePool *pool;
  790.     AstArray<AstBrackets *> *brackets;
  791.  
  792. public:
  793.     Ast *type;
  794.  
  795.     AstArrayType(StoragePool *pool_) : pool(pool_),
  796.                                        brackets(NULL)
  797.     {
  798.         Ast::kind = Ast::ARRAY;
  799.         Ast::class_tag = Ast::NO_TAG;
  800.         Ast::generated = 0;
  801.     }
  802.  
  803.     virtual ~AstArrayType();
  804.  
  805.     inline AstBrackets *&Brackets(int i) { return (*brackets)[i]; }
  806.     inline int NumBrackets() { return (brackets ? brackets -> Length() : 0); }
  807.     inline void AllocateBrackets(int estimate = 0);
  808.     inline void AddBrackets(AstBrackets *);
  809.  
  810. #ifdef TEST
  811.     virtual void Print(LexStream &);
  812. #endif
  813.  
  814.     virtual Ast *Clone(StoragePool *);
  815.  
  816.     virtual LexStream::TokenIndex LeftToken()  { return type -> LeftToken(); }
  817.     virtual LexStream::TokenIndex RightToken() { return Brackets(NumBrackets() - 1) -> RightToken(); }
  818. };
  819.  
  820.  
  821. //
  822. // Name --> SimpleName
  823. //        | FieldAccess
  824. //
  825. // SimpleName --> <IDENTIFIER, identifier_token>
  826. //
  827. class AstSimpleName : public AstExpression
  828. {
  829. public:
  830.     LexStream::TokenIndex identifier_token;
  831.  
  832.     //
  833.     // When a simple_name refers to a member in an enclosing scope,
  834.     // it is mapped into a new expression that creates a path to
  835.     // the member in question.
  836.     //
  837.     AstExpression *resolution_opt;
  838.  
  839.     AstSimpleName(LexStream::TokenIndex token_) : identifier_token(token_),
  840.                                                   resolution_opt(NULL)
  841.     {
  842.         Ast::kind = Ast::IDENTIFIER;
  843.         Ast::class_tag = Ast::EXPRESSION;
  844.         Ast::generated = 0;
  845.         AstExpression::value = NULL;
  846.         AstExpression::symbol = NULL;
  847.     }
  848.  
  849.     virtual ~AstSimpleName();
  850.  
  851. #ifdef TEST
  852.     virtual void Print(LexStream &);
  853. #endif
  854.  
  855.     virtual Ast *Clone(StoragePool *);
  856.  
  857.     virtual LexStream::TokenIndex LeftToken()  { return identifier_token; }
  858.     virtual LexStream::TokenIndex RightToken() { return identifier_token; }
  859. };
  860.  
  861. //
  862. // PackageDeclaration --> <PACKAGE, package_token, Name, ;_token>
  863. //
  864. class AstPackageDeclaration : public Ast
  865. {
  866. public:
  867.     LexStream::TokenIndex package_token;
  868.     AstExpression *name;
  869.     LexStream::TokenIndex semicolon_token;
  870.  
  871.     AstPackageDeclaration()
  872.     {
  873.         Ast::kind = Ast::PACKAGE;
  874.         Ast::class_tag = Ast::NO_TAG;
  875.         Ast::generated = 0;
  876.     }
  877.  
  878.     virtual ~AstPackageDeclaration();
  879.  
  880. #ifdef TEST
  881.     virtual void Print(LexStream &);
  882. #endif
  883.  
  884.     virtual Ast *Clone(StoragePool *);
  885.  
  886.     virtual LexStream::TokenIndex LeftToken()  { return package_token; }
  887.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  888. };
  889.  
  890. //
  891. // ImportDeclaration --> <IMPORT, import_token, Name, *_token_opt, ;_token>
  892. //
  893. class AstImportDeclaration : public Ast
  894. {
  895. public:
  896.     LexStream::TokenIndex import_token;
  897.     AstExpression *name;
  898.     LexStream::TokenIndex star_token_opt;       // import on demand
  899.     LexStream::TokenIndex semicolon_token;
  900.  
  901.     AstImportDeclaration()
  902.     {
  903.         Ast::kind = Ast::IMPORT;
  904.         Ast::class_tag = Ast::NO_TAG;
  905.         Ast::generated = 0;
  906.     }
  907.  
  908.     virtual ~AstImportDeclaration();
  909.  
  910. #ifdef TEST
  911.     virtual void Print(LexStream &);
  912. #endif
  913.  
  914.     virtual Ast *Clone(StoragePool *);
  915.  
  916.     virtual LexStream::TokenIndex LeftToken()  { return import_token; }
  917.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  918. };
  919.  
  920. //
  921. // CompilationUnit --> <COMPILATION,     PackageDeclaration_opt, ImportDeclarations, TypeDeclarations>
  922. //                   | <BAD_COMPILATION, PackageDeclaration_opt, ImportDeclarations, TypeDeclarations>
  923. //                   | <EMPTY_COMPILATION, PackageDeclaration_opt, ImportDeclarations, TypeDeclarations>
  924. //
  925. class AstCompilationUnit : public Ast
  926. {
  927. private:
  928.  
  929.     StoragePool *pool;
  930.     AstArray<AstImportDeclaration *> *import_declarations;
  931.     AstArray<Ast *> *type_declarations;
  932.  
  933. public:
  934.     StoragePool *ast_pool;
  935.  
  936.     AstPackageDeclaration *package_declaration_opt;
  937.  
  938.     AstCompilationUnit(StoragePool *pool_) : pool(pool_),
  939.                                              import_declarations(NULL),
  940.                                              type_declarations(NULL)
  941.     {
  942.         Ast::kind = Ast::COMPILATION;
  943.         Ast::class_tag = Ast::NO_TAG;
  944.         Ast::generated = 0;
  945.     }
  946.  
  947.     virtual ~AstCompilationUnit();
  948.  
  949.     void FreeAst();
  950.  
  951.     inline AstImportDeclaration *&ImportDeclaration(int i) { return (*import_declarations)[i]; }
  952.     inline int NumImportDeclarations() { return (import_declarations ? import_declarations -> Length() : 0); }
  953.     inline void AllocateImportDeclarations(int estimate = 0);
  954.     inline void AddImportDeclaration(AstImportDeclaration *);
  955.  
  956.     inline void ResetTypeDeclarations(int n) { if (type_declarations) type_declarations -> Reset(n); }
  957.     inline Ast *&TypeDeclaration(int i) { return (*type_declarations)[i]; }
  958.     inline int NumTypeDeclarations() { return (type_declarations ? type_declarations -> Length() : 0); }
  959.     inline void AllocateTypeDeclarations(int estimate = 0);
  960.     inline void AddTypeDeclaration(Ast *);
  961.  
  962. #ifdef TEST
  963.     virtual void Print(LexStream &);
  964. #endif
  965.  
  966.     virtual Ast *Clone(StoragePool *);
  967.  
  968.     virtual LexStream::TokenIndex LeftToken()
  969.     {
  970.         if (package_declaration_opt)
  971.              return package_declaration_opt -> LeftToken();
  972.         else if (NumImportDeclarations() > 0)
  973.              return ImportDeclaration(0) -> LeftToken();
  974.         else if (NumTypeDeclarations() > 0)
  975.              return TypeDeclaration(0) -> LeftToken();
  976.  
  977.         return 0;
  978.     }
  979.  
  980.     virtual LexStream::TokenIndex RightToken()
  981.     {
  982.         if (NumTypeDeclarations() > 0)
  983.              return TypeDeclaration(NumTypeDeclarations() - 1) -> RightToken();
  984.         else if (NumImportDeclarations() > 0)
  985.              return ImportDeclaration(NumImportDeclarations() - 1) -> RightToken();
  986.         else if (package_declaration_opt)
  987.              return package_declaration_opt -> RightToken();
  988.  
  989.         return 0;
  990.     }
  991. };
  992.  
  993.  
  994. //
  995. // Modifier --> <ModifierKind, ModifierName>
  996. //
  997. // ModifierKind --> PUBLIC | PROTECTED | PRIVATE | STATIC | ABSTRACT | FINAL | NATIVE
  998. //                  SYNCHRONIZED | TRANSIENT | VOLATILE
  999. //
  1000. // ModifierName --> public_token | protected_token | private_token | static_token | abstract_token |
  1001. //                  final_token | native_token | synchronized_token | transient_token | volatile_token
  1002. //
  1003. class AstModifier : public Ast
  1004. {
  1005. public:
  1006.     LexStream::TokenIndex modifier_kind_token;
  1007.  
  1008.     AstModifier(Ast::Kind kind_, LexStream::TokenIndex token_) : modifier_kind_token(token_)
  1009.     {
  1010.         Ast::kind = kind_;
  1011.         Ast::class_tag = Ast::MODIFIER;
  1012.         Ast::generated = 0;
  1013.     }
  1014.  
  1015.     virtual ~AstModifier();
  1016.  
  1017. #ifdef TEST
  1018.     virtual void Print(LexStream &);
  1019. #endif
  1020.  
  1021.     virtual Ast *Clone(StoragePool *);
  1022.  
  1023.     virtual LexStream::TokenIndex LeftToken()  { return modifier_kind_token; }
  1024.     virtual LexStream::TokenIndex RightToken() { return modifier_kind_token; }
  1025. };
  1026.  
  1027.  
  1028. //
  1029. // EmptyDeclaration --> <EMPTY_DECLARATION, ;_token>
  1030. //
  1031. class AstEmptyDeclaration : public Ast
  1032. {
  1033. public:
  1034.     LexStream::TokenIndex semicolon_token;
  1035.  
  1036.     AstEmptyDeclaration(LexStream::TokenIndex token_) : semicolon_token(token_)
  1037.     {
  1038.         Ast::kind = Ast::EMPTY_DECLARATION;
  1039.         Ast::class_tag = Ast::NO_TAG;
  1040.         Ast::generated = 0;
  1041.     }
  1042.  
  1043.     virtual ~AstEmptyDeclaration();
  1044.  
  1045. #ifdef TEST
  1046.     virtual void Print(LexStream &);
  1047. #endif
  1048.  
  1049.     virtual Ast *Clone(StoragePool *);
  1050.  
  1051.     virtual LexStream::TokenIndex LeftToken() { return semicolon_token; }
  1052.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  1053. };
  1054.  
  1055. //
  1056. // ClassBody --> <CLASS_BODY, {_token, ClassBodyDeclarations, }_token>
  1057. //
  1058. class AstClassBody : public Ast
  1059. {
  1060. private:
  1061.     friend class Parser;
  1062.  
  1063.     StoragePool *pool;
  1064.     AstArray<Ast *> *class_body_declarations;
  1065.  
  1066.     AstArray<AstFieldDeclaration *> *instance_variables;
  1067.     AstArray<AstFieldDeclaration *> *class_variables;
  1068.     AstArray<AstMethodDeclaration *> *methods;
  1069.     AstArray<AstConstructorDeclaration *> *constructors;
  1070.     AstArray<AstStaticInitializer *> *static_initializers;
  1071.     AstArray<AstClassDeclaration *> *inner_classes;
  1072.     AstArray<AstInterfaceDeclaration *> *inner_interfaces;
  1073.     AstArray<AstBlock *> *blocks;
  1074.     AstArray<AstEmptyDeclaration *> *empty_declarations;
  1075.  
  1076. public:
  1077.  
  1078.     AstConstructorDeclaration *default_constructor;
  1079.  
  1080.     AstBlock *this_block; // used by inner classes to initialize this$1, ...this$n fields
  1081.  
  1082.     LexStream::TokenIndex left_brace_token;
  1083.     LexStream::TokenIndex right_brace_token;
  1084.  
  1085.     inline void mark_unparsed() { Ast::class_tag = Ast::UNPARSED; }
  1086.     inline void mark_parsed()   { Ast::class_tag = Ast::NO_TAG; }
  1087.  
  1088.     AstClassBody(StoragePool *pool_) : pool(pool_),
  1089.                                        class_body_declarations(NULL),
  1090.                                        default_constructor(NULL),
  1091.                                        instance_variables(NULL),
  1092.                                        class_variables(NULL),
  1093.                                        methods(NULL),
  1094.                                        constructors(NULL),
  1095.                                        static_initializers(NULL),
  1096.                                        inner_classes(NULL),
  1097.                                        inner_interfaces(NULL),
  1098.                                        blocks(NULL),
  1099.                                        empty_declarations(NULL),
  1100.                                        this_block(NULL)
  1101.     {
  1102.         Ast::kind = Ast::CLASS_BODY;
  1103.         Ast::class_tag = Ast::NO_TAG;
  1104.         Ast::generated = 0;
  1105.     }
  1106.  
  1107.     virtual ~AstClassBody();
  1108.  
  1109.     inline Ast *&ClassBodyDeclaration(int i) { return (*class_body_declarations)[i]; }
  1110.     inline int NumClassBodyDeclarations() { return (class_body_declarations ? class_body_declarations -> Length() : 0); }
  1111.     inline void AllocateClassBodyDeclarations(int estimate = 0);
  1112.     inline void AddClassBodyDeclaration(Ast *);
  1113.  
  1114.     inline AstFieldDeclaration *&InstanceVariable(int i) { return (*instance_variables)[i]; }
  1115.     inline int NumInstanceVariables() { return (instance_variables ? instance_variables -> Length() : 0); }
  1116.     inline void AllocateInstanceVariables(int estimate = 0);
  1117.     inline void AddInstanceVariable(AstFieldDeclaration *);
  1118.  
  1119.     inline AstFieldDeclaration *&ClassVariable(int i) { return (*class_variables)[i]; }
  1120.     inline int NumClassVariables() { return (class_variables ? class_variables -> Length() : 0); }
  1121.     inline void AllocateClassVariables(int estimate = 0);
  1122.     inline void AddClassVariable(AstFieldDeclaration *);
  1123.  
  1124.     inline AstMethodDeclaration *&Method(int i) { return (*methods)[i]; }
  1125.     inline int NumMethods() { return (methods ? methods -> Length() : 0); }
  1126.     inline void AllocateMethods(int estimate = 0);
  1127.     inline void AddMethod(AstMethodDeclaration *);
  1128.  
  1129.     inline AstConstructorDeclaration *&Constructor(int i) { return (*constructors)[i]; }
  1130.     inline int NumConstructors() { return (constructors ? constructors -> Length() : 0); }
  1131.     inline void AllocateConstructors(int estimate = 0);
  1132.     inline void AddConstructor(AstConstructorDeclaration *);
  1133.  
  1134.     inline AstStaticInitializer *&StaticInitializer(int i) { return (*static_initializers)[i]; }
  1135.     inline int NumStaticInitializers() { return (static_initializers ? static_initializers -> Length() : 0); }
  1136.     inline void AllocateStaticInitializers(int estimate = 0);
  1137.     inline void AddStaticInitializer(AstStaticInitializer *);
  1138.  
  1139.     inline AstClassDeclaration *&NestedClass(int i) { return (*inner_classes)[i]; }
  1140.     inline int NumNestedClasses() { return (inner_classes ? inner_classes -> Length() : 0); }
  1141.     inline void AllocateNestedClasses(int estimate = 0);
  1142.     inline void AddNestedClass(AstClassDeclaration *);
  1143.  
  1144.     inline AstInterfaceDeclaration *&NestedInterface(int i) { return (*inner_interfaces)[i]; }
  1145.     inline int NumNestedInterfaces() { return (inner_interfaces ? inner_interfaces -> Length() : 0); }
  1146.     inline void AllocateNestedInterfaces(int estimate = 0);
  1147.     inline void AddNestedInterface(AstInterfaceDeclaration *);
  1148.  
  1149.     inline AstBlock *&Block(int i) { return (*blocks)[i]; }
  1150.     inline int NumBlocks() { return (blocks ? blocks -> Length() : 0); }
  1151.     inline void AllocateBlocks(int estimate = 0);
  1152.     inline void AddBlock(AstBlock *);
  1153.  
  1154.     inline AstEmptyDeclaration *&EmptyDeclaration(int i) { return (*empty_declarations)[i]; }
  1155.     inline int NumEmptyDeclarations() { return (empty_declarations ? empty_declarations -> Length() : 0); }
  1156.     inline void AllocateEmptyDeclarations(int estimate = 0);
  1157.     inline void AddEmptyDeclaration(AstEmptyDeclaration *);
  1158.  
  1159. #ifdef TEST
  1160.     virtual void Print(LexStream &);
  1161. #endif
  1162.  
  1163.     virtual Ast *Clone(StoragePool *);
  1164.  
  1165.     virtual LexStream::TokenIndex LeftToken() { return left_brace_token; }
  1166.     virtual LexStream::TokenIndex RightToken() { return right_brace_token; }
  1167. };
  1168.  
  1169.  
  1170.  
  1171. //
  1172. // TypeDeclaration --> ClassDeclaration
  1173. //                   | InterfaceDeclaration
  1174. //                   | EmptyDeclaration
  1175. //
  1176. // ClassDeclaration --> <CLASS, ClassModifiers, class_token, identifier_token, Super_opt, Interfaces, ClassBody>
  1177. //
  1178. // Super --> Name
  1179. //
  1180. // Interface --> Name
  1181. //
  1182. // ClassModifier --> Modifier  (ABSTRACT, FINAL or PUBLIC)
  1183. //
  1184. // ClassBodyDeclaration --> FieldDeclaration
  1185. //                        | MethodDeclaration
  1186. //                        | ConstructorDeclaration
  1187. //                        | StaticInitializer
  1188. //
  1189. class AstClassDeclaration : public AstStatement
  1190. {
  1191.     StoragePool *pool;
  1192.     AstArray<AstModifier *> *class_modifiers;
  1193.     AstArray<AstExpression *> *interfaces;
  1194.  
  1195. public:
  1196.     SemanticEnvironment *semantic_environment;
  1197.  
  1198.     LexStream::TokenIndex class_token;
  1199.     LexStream::TokenIndex identifier_token;
  1200.     Ast *super_opt;
  1201.     AstClassBody *class_body;
  1202.  
  1203.     AstClassDeclaration(StoragePool *pool_) : pool(pool_),
  1204.                                               class_modifiers(NULL),
  1205.                                               interfaces(NULL),
  1206.                                               semantic_environment(NULL)
  1207.     {
  1208.         Ast::kind = Ast::CLASS;
  1209.         Ast::class_tag = Ast::NO_TAG;
  1210.         Ast::generated = 0;
  1211.     }
  1212.  
  1213.     virtual ~AstClassDeclaration();
  1214.  
  1215.     bool IsValid() { return semantic_environment != NULL; }
  1216.  
  1217.     inline void MarkLocal()
  1218.     {
  1219.         Ast::class_tag = Ast::STATEMENT;
  1220.         AstStatement::is_reachable = true;
  1221.         AstStatement::can_complete_normally = true;
  1222.     }
  1223.  
  1224.     inline AstModifier *&ClassModifier(int i) { return (*class_modifiers)[i]; }
  1225.     inline int NumClassModifiers() { return (class_modifiers ? class_modifiers -> Length() : 0); }
  1226.     inline void AllocateClassModifiers(int estimate = 0);
  1227.     inline void AddClassModifier(AstModifier *);
  1228.  
  1229.     inline AstExpression *&Interface(int i) { return (*interfaces)[i]; }
  1230.     inline int NumInterfaces() { return (interfaces ? interfaces -> Length() : 0); }
  1231.     inline void AllocateInterfaces(int estimate = 0);
  1232.     inline void AddInterface(AstExpression *);
  1233.  
  1234. #ifdef TEST
  1235.     virtual void Print(LexStream &);
  1236. #endif
  1237.  
  1238.     virtual Ast *Clone(StoragePool *);
  1239.  
  1240.     virtual LexStream::TokenIndex LeftToken()
  1241.     {
  1242.         return (NumClassModifiers() > 0 ? (*class_modifiers)[0] -> LeftToken() : class_token);
  1243.     }
  1244.     virtual LexStream::TokenIndex RightToken() { return class_body -> RightToken(); }
  1245. };
  1246.  
  1247.  
  1248. //
  1249. // VariableInitializer --> Expression
  1250. //                       | ArrayInitializer
  1251. //
  1252. // ArrayInitializer --> <ARRAY_INITIALIZER, {_token, VariableInitializers, }_token>
  1253. //
  1254. class AstArrayInitializer : public Ast
  1255. {
  1256. private:
  1257.  
  1258.     StoragePool *pool;
  1259.     AstArray<Ast *> *variable_initializers;
  1260.  
  1261. public:
  1262.     LexStream::TokenIndex left_brace_token;
  1263.     LexStream::TokenIndex right_brace_token;
  1264.  
  1265.     AstArrayInitializer(StoragePool *pool_) : pool(pool_),
  1266.                                               variable_initializers(NULL)
  1267.     {
  1268.         Ast::kind = Ast::ARRAY_INITIALIZER;
  1269.         Ast::class_tag = Ast::NO_TAG;
  1270.         Ast::generated = 0;
  1271.     }
  1272.  
  1273.     virtual ~AstArrayInitializer();
  1274.  
  1275.     inline Ast *&VariableInitializer(int i) { return (*variable_initializers)[i]; }
  1276.     inline int NumVariableInitializers() { return (variable_initializers ? variable_initializers -> Length() : 0); }
  1277.     inline void AllocateVariableInitializers(int estimate = 0);
  1278.     inline void AddVariableInitializer(Ast *);
  1279.  
  1280. #ifdef TEST
  1281.     virtual void Print(LexStream &);
  1282. #endif
  1283.  
  1284.     virtual Ast *Clone(StoragePool *);
  1285.  
  1286.     virtual LexStream::TokenIndex LeftToken() { return left_brace_token; }
  1287.     virtual LexStream::TokenIndex RightToken() { return right_brace_token; }
  1288. };
  1289.  
  1290.  
  1291. //
  1292. // VariableDeclaratorId --> <VARIABLE_DECLARATOR_NAME, identifier_token, Brackets>
  1293. //
  1294. class AstVariableDeclaratorId : public Ast
  1295. {
  1296. private:
  1297.  
  1298.     StoragePool *pool;
  1299.     AstArray<AstBrackets *> *brackets;
  1300.  
  1301. public:
  1302.  
  1303.     LexStream::TokenIndex identifier_token;
  1304.  
  1305.     AstVariableDeclaratorId(StoragePool *pool_) : pool(pool_),
  1306.                                                   brackets(NULL)
  1307.     {
  1308.         Ast::kind = Ast::VARIABLE_DECLARATOR_NAME;
  1309.         Ast::class_tag = Ast::NO_TAG;
  1310.         Ast::generated = 0;
  1311.     }
  1312.  
  1313.     virtual ~AstVariableDeclaratorId();
  1314.  
  1315.     inline AstBrackets *&Brackets(int i) { return (*brackets)[i]; }
  1316.     inline int NumBrackets() { return (brackets ? brackets -> Length() : 0); }
  1317.     inline void AllocateBrackets(int estimate = 0);
  1318.     inline void AddBrackets(AstBrackets *);
  1319.  
  1320. #ifdef TEST
  1321.     virtual void Print(LexStream &);
  1322. #endif
  1323.  
  1324.     virtual Ast *Clone(StoragePool *);
  1325.  
  1326.     virtual LexStream::TokenIndex LeftToken()  { return identifier_token; }
  1327.     virtual LexStream::TokenIndex RightToken()
  1328.     {
  1329.         return (NumBrackets() > 0 ? (*brackets)[NumBrackets() - 1] -> RightToken() : identifier_token);
  1330.     }
  1331. };
  1332.  
  1333.  
  1334. //
  1335. // VariableDeclarator --> <VARIABLE_DECLARATOR, VariableDeclaratorId, VariableInitializer_opt>
  1336. //
  1337. class AstVariableDeclarator : public Ast
  1338. {
  1339. public:
  1340.     VariableSymbol *symbol;
  1341.     bool pending; // when true, this variable signals that the variable_initializer_opt for this variable is currently being evaluated
  1342.  
  1343.     AstVariableDeclaratorId *variable_declarator_name;
  1344.     Ast *variable_initializer_opt;
  1345.  
  1346.     AstVariableDeclarator() : symbol(NULL),
  1347.                               pending(false)
  1348.     {
  1349.         Ast::kind = Ast::VARIABLE_DECLARATOR;
  1350.         Ast::class_tag = Ast::NO_TAG;
  1351.         Ast::generated = 0;
  1352.     }
  1353.  
  1354.     virtual ~AstVariableDeclarator();
  1355.  
  1356. #ifdef TEST
  1357.     virtual void Print(LexStream &);
  1358. #endif
  1359.  
  1360.     virtual Ast *Clone(StoragePool *);
  1361.  
  1362.     virtual LexStream::TokenIndex LeftToken() { return variable_declarator_name -> LeftToken(); }
  1363.  
  1364.     virtual LexStream::TokenIndex RightToken()
  1365.     {
  1366.         return (variable_initializer_opt ?
  1367.                 variable_initializer_opt -> RightToken() :
  1368.                 variable_declarator_name -> RightToken());
  1369.     }
  1370. };
  1371.  
  1372.  
  1373. //
  1374. // FieldDeclaration --> <FIELD, VariableModifiers, Type, VariableDeclarators, ;_token>
  1375. //
  1376. // FieldModifier --> Modifier (PUBLIC, PROTECTED, PRIVATE, FINAL, STATIC, TRANSIENT or VOLATILE)
  1377. //
  1378. class AstFieldDeclaration : public Ast
  1379. {
  1380.     StoragePool *pool;
  1381.     AstArray<AstModifier *> *variable_modifiers;
  1382.     AstArray<AstVariableDeclarator *> *variable_declarators;
  1383.  
  1384. public:
  1385.  
  1386.     Ast *type;
  1387.     LexStream::TokenIndex semicolon_token;
  1388.  
  1389.     AstFieldDeclaration(StoragePool *pool_) : pool(pool_),
  1390.                                               variable_modifiers(NULL),
  1391.                                               variable_declarators(NULL)
  1392.     {
  1393.         Ast::kind = Ast::FIELD;
  1394.         Ast::class_tag = Ast::NO_TAG;
  1395.         Ast::generated = 0;
  1396.     }
  1397.  
  1398.     virtual ~AstFieldDeclaration();
  1399.  
  1400.     inline void MarkStatic() { Ast::class_tag = Ast::STATIC_FIELD; }
  1401.  
  1402.     inline AstModifier *&VariableModifier(int i) { return (*variable_modifiers)[i]; }
  1403.     inline int NumVariableModifiers() { return (variable_modifiers ? variable_modifiers -> Length() : 0); }
  1404.     inline void AllocateVariableModifiers(int estimate = 0);
  1405.     inline void AddVariableModifier(AstModifier *);
  1406.  
  1407.     inline AstVariableDeclarator *&VariableDeclarator(int i) { return (*variable_declarators)[i]; }
  1408.     inline int NumVariableDeclarators() { return (variable_declarators ? variable_declarators -> Length() : 0); }
  1409.     inline void AllocateVariableDeclarators(int estimate = 0);
  1410.     inline void AddVariableDeclarator(AstVariableDeclarator *);
  1411.  
  1412. #ifdef TEST
  1413.     virtual void Print(LexStream &);
  1414. #endif
  1415.  
  1416.     virtual Ast *Clone(StoragePool *);
  1417.  
  1418.     virtual LexStream::TokenIndex LeftToken()
  1419.     {
  1420.         return (NumVariableModifiers() > 0 ? (*variable_modifiers)[0] -> LeftToken() : type -> LeftToken());
  1421.     }
  1422.  
  1423.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  1424. };
  1425.  
  1426.  
  1427. //
  1428. // FormalParameter --> <PARAMETER, Type, VariableDeclaratorId>
  1429. //
  1430. class AstFormalParameter : public Ast
  1431. {
  1432.     StoragePool *pool;
  1433.     AstArray<AstModifier *> *parameter_modifiers;
  1434.  
  1435. public:
  1436.  
  1437.     Ast *type;
  1438.     AstVariableDeclarator *formal_declarator;
  1439.  
  1440.     AstFormalParameter(StoragePool *pool_) : pool(pool_),
  1441.                                              parameter_modifiers(NULL)
  1442.     {
  1443.         Ast::kind = Ast::PARAMETER;
  1444.         Ast::class_tag = Ast::NO_TAG;
  1445.         Ast::generated = 0;
  1446.     }
  1447.  
  1448.     virtual ~AstFormalParameter();
  1449.  
  1450.     inline AstModifier *&ParameterModifier(int i) { return (*parameter_modifiers)[i]; }
  1451.     inline int NumParameterModifiers() { return (parameter_modifiers ? parameter_modifiers -> Length() : 0); }
  1452.     inline void AllocateParameterModifiers(int estimate = 0);
  1453.     inline void AddParameterModifier(AstModifier *);
  1454.  
  1455. #ifdef TEST
  1456.     virtual void Print(LexStream &);
  1457. #endif
  1458.  
  1459.     virtual Ast *Clone(StoragePool *);
  1460.  
  1461.     virtual LexStream::TokenIndex LeftToken()
  1462.     {
  1463.        return (NumParameterModifiers() > 0 ? (*parameter_modifiers)[0] -> LeftToken() : type -> LeftToken());
  1464.     }
  1465.     virtual LexStream::TokenIndex RightToken() { return formal_declarator -> RightToken(); }
  1466. };
  1467.  
  1468.  
  1469. //
  1470. // MethodDeclarator --> <METHOD_DECLARATOR, identifier_token, (_token, FormalParameters, )_token, Brackets>
  1471. //
  1472. class AstMethodDeclarator : public Ast
  1473. {
  1474. private:
  1475.  
  1476.     StoragePool *pool;
  1477.     AstArray<AstBrackets *> *brackets;
  1478.     AstArray<AstFormalParameter *> *formal_parameters;
  1479.  
  1480. public:
  1481.     LexStream::TokenIndex identifier_token;
  1482.     LexStream::TokenIndex left_parenthesis_token;
  1483.     LexStream::TokenIndex right_parenthesis_token;
  1484.  
  1485.     AstMethodDeclarator(StoragePool *pool_) : pool(pool_),
  1486.                                               brackets(NULL),
  1487.                                               formal_parameters(NULL)
  1488.     {
  1489.         Ast::kind = Ast::METHOD_DECLARATOR;
  1490.         Ast::class_tag = Ast::NO_TAG;
  1491.         Ast::generated = 0;
  1492.     }
  1493.  
  1494.     virtual ~AstMethodDeclarator();
  1495.  
  1496.     inline AstBrackets *&Brackets(int i) { return (*brackets)[i]; }
  1497.     inline int NumBrackets() { return (brackets ? brackets -> Length() : 0); }
  1498.     inline void AllocateBrackets(int estimate = 0);
  1499.     inline void AddBrackets(AstBrackets *);
  1500.  
  1501.     inline AstFormalParameter *&FormalParameter(int i) { return (*formal_parameters)[i]; }
  1502.     inline int NumFormalParameters() { return (formal_parameters ? formal_parameters -> Length() : 0); }
  1503.     inline void AllocateFormalParameters(int estimate = 0);
  1504.     inline void AddFormalParameter(AstFormalParameter *);
  1505.  
  1506. #ifdef TEST
  1507.     virtual void Print(LexStream &);
  1508. #endif
  1509.  
  1510.     virtual Ast *Clone(StoragePool *);
  1511.  
  1512.     virtual LexStream::TokenIndex LeftToken() { return identifier_token; }
  1513.  
  1514.     virtual LexStream::TokenIndex RightToken()
  1515.     {
  1516.         return (NumBrackets() ? Brackets(NumBrackets() - 1) -> RightToken() : right_parenthesis_token);
  1517.     }
  1518. };
  1519.  
  1520.  
  1521. //
  1522. // MethodDeclaration --> <METHOD, MethodModifiers, Type, MethodDeclarator, Throws, MethodBody>
  1523. //
  1524. // MethodModifier --> Modifier (PUBLIC, PROTECTED, PRIVATE, STATIC, ABSTRACT, FINAL, NATIVE or SYNCHRONIZED)
  1525. //
  1526. // Throws --> Names
  1527. //
  1528. // MethodBody --> Block
  1529. //              | EmptyStatement
  1530. //
  1531. class AstMethodDeclaration : public Ast
  1532. {
  1533.     StoragePool *pool;
  1534.     AstArray<AstModifier *> *method_modifiers;
  1535.     AstArray<AstExpression *> *throws;
  1536.  
  1537. public:
  1538.     MethodSymbol *method_symbol;
  1539.  
  1540.     Ast *type;
  1541.     AstMethodDeclarator *method_declarator;
  1542.     AstStatement *method_body;
  1543.  
  1544.     AstMethodDeclaration(StoragePool *pool_) : pool(pool_),
  1545.                                                method_modifiers(NULL),
  1546.                                                throws(NULL),
  1547.                                                method_symbol(NULL)
  1548.     {
  1549.         Ast::kind = Ast::METHOD;
  1550.         Ast::class_tag = Ast::NO_TAG;
  1551.         Ast::generated = 0;
  1552.     }
  1553.  
  1554.     virtual ~AstMethodDeclaration();
  1555.  
  1556.     bool IsValid() { return method_symbol != NULL; }
  1557.  
  1558.     bool IsSignature() { return (method_body -> EmptyStatementCast() != NULL); }
  1559.  
  1560.     inline AstModifier *&MethodModifier(int i) { return (*method_modifiers)[i]; }
  1561.     inline int NumMethodModifiers() { return (method_modifiers ? method_modifiers -> Length() : 0); }
  1562.     inline void AllocateMethodModifiers(int estimate = 0);
  1563.     inline void AddMethodModifier(AstModifier *);
  1564.  
  1565.     inline AstExpression *&Throw(int i) { return (*throws)[i]; }
  1566.     inline int NumThrows() { return (throws ? throws -> Length() : 0); }
  1567.     inline void AllocateThrows(int estimate = 0);
  1568.     inline void AddThrow(AstExpression *);
  1569.  
  1570. #ifdef TEST
  1571.     virtual void Print(LexStream &);
  1572. #endif
  1573.  
  1574.     virtual Ast *Clone(StoragePool *);
  1575.  
  1576.     virtual LexStream::TokenIndex LeftToken()
  1577.     {
  1578.         return (NumMethodModifiers() > 0 ? (*method_modifiers)[0] -> LeftToken() : type -> LeftToken());
  1579.     }
  1580.     virtual LexStream::TokenIndex RightToken() { return method_body -> RightToken(); }
  1581. };
  1582.  
  1583. //
  1584. // StaticInitializer --> <STATIC_INITIALIZER, static_token, Block>
  1585. //
  1586. class AstStaticInitializer : public Ast
  1587. {
  1588. public:
  1589.     LexStream::TokenIndex static_token;
  1590.     AstBlock *block;
  1591.  
  1592.     AstStaticInitializer()
  1593.     {
  1594.         Ast::kind = Ast::STATIC_INITIALIZER;
  1595.         Ast::class_tag = Ast::NO_TAG;
  1596.         Ast::generated = 0;
  1597.     }
  1598.  
  1599.     virtual ~AstStaticInitializer();
  1600.  
  1601. #ifdef TEST
  1602.     virtual void Print(LexStream &);
  1603. #endif
  1604.  
  1605.     virtual Ast *Clone(StoragePool *);
  1606.  
  1607.     virtual LexStream::TokenIndex LeftToken() { return static_token; }
  1608.     virtual LexStream::TokenIndex RightToken() { return block -> RightToken(); }
  1609. };
  1610.  
  1611.  
  1612. //
  1613. // ThisCall --> <THIS_CALL, this_token, (_token, Arguments, )_token, ;_token>
  1614. //
  1615. // Argument --> Expression
  1616. //
  1617. class AstThisCall : public AstStatement
  1618. {
  1619. private:
  1620.  
  1621.     StoragePool *pool;
  1622.     AstArray<AstExpression *> *arguments;
  1623.     AstArray<AstExpression *> *local_arguments_opt; // used only for local classes that use enclosed local variables
  1624.  
  1625. public:
  1626.     MethodSymbol *symbol;
  1627.  
  1628.     AstExpression *base_opt;
  1629.     LexStream::TokenIndex dot_token_opt;
  1630.     LexStream::TokenIndex this_token;
  1631.     LexStream::TokenIndex left_parenthesis_token;
  1632.     LexStream::TokenIndex right_parenthesis_token;
  1633.     LexStream::TokenIndex semicolon_token;
  1634.  
  1635.     AstThisCall(StoragePool *pool_) : pool(pool_),
  1636.                                       arguments(NULL),
  1637.                                       local_arguments_opt(NULL),
  1638.                                       symbol(NULL)
  1639.     {
  1640.         Ast::kind = Ast::THIS_CALL;
  1641.         Ast::class_tag = Ast::STATEMENT;
  1642.         Ast::generated = 0;
  1643.         AstStatement::is_reachable = false;
  1644.         AstStatement::can_complete_normally = false;
  1645.     }
  1646.  
  1647.     virtual ~AstThisCall();
  1648.  
  1649.     inline AstExpression *&Argument(int i) { return (*arguments)[i]; }
  1650.     inline int NumArguments() { return (arguments ? arguments -> Length() : 0); }
  1651.     inline void AllocateArguments(int estimate = 0);
  1652.     inline void AddArgument(AstExpression *);
  1653.  
  1654.     inline AstExpression *&LocalArgument(int i) { return (*local_arguments_opt)[i]; }
  1655.     inline int NumLocalArguments() { return (local_arguments_opt ? local_arguments_opt -> Length() : 0); }
  1656.     inline void AllocateLocalArguments(int estimate = 0);
  1657.     inline void AddLocalArgument(AstExpression *);
  1658.  
  1659. #ifdef TEST
  1660.     virtual void Print(LexStream &);
  1661. #endif
  1662.  
  1663.     virtual Ast *Clone(StoragePool *);
  1664.  
  1665.     virtual LexStream::TokenIndex LeftToken() { return this_token; }
  1666.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  1667. };
  1668.  
  1669.  
  1670. //
  1671. // SuperCall --> <SUPER_CALL, super_token, (_token, Arguments, )_token, ;_token>
  1672. //             | <SUPER_CALL, SuperField, (_token, Arguments, )_token, ;_token>
  1673. //
  1674. class AstSuperCall : public AstStatement
  1675. {
  1676. private:
  1677.  
  1678.     StoragePool *pool;
  1679.     AstArray<AstExpression *> *arguments;
  1680.     AstArray<AstExpression *> *local_arguments_opt; // used only for local classes that use enclosed local variables
  1681.  
  1682.     bool add_null_argument;
  1683.  
  1684. public:
  1685.     MethodSymbol *symbol;
  1686.  
  1687.     AstExpression *base_opt;
  1688.     LexStream::TokenIndex dot_token_opt;
  1689.     LexStream::TokenIndex super_token;
  1690.     LexStream::TokenIndex left_parenthesis_token;
  1691.     LexStream::TokenIndex right_parenthesis_token;
  1692.     LexStream::TokenIndex semicolon_token;
  1693.  
  1694.     AstSuperCall(StoragePool *pool_) : pool(pool_),
  1695.                                        arguments(NULL),
  1696.                                        local_arguments_opt(NULL),
  1697.                                        add_null_argument(false),
  1698.                                        symbol(NULL)
  1699.     {
  1700.         Ast::kind = Ast::SUPER_CALL;
  1701.         Ast::class_tag = Ast::STATEMENT;
  1702.         Ast::generated = 0;
  1703.         AstStatement::is_reachable = false;
  1704.         AstStatement::can_complete_normally = false;
  1705.     }
  1706.  
  1707.     virtual ~AstSuperCall();
  1708.  
  1709.     inline AstExpression *&Argument(int i) { return (*arguments)[i]; }
  1710.     inline int NumArguments() { return (arguments ? arguments -> Length() : 0); }
  1711.     inline void AllocateArguments(int estimate = 0);
  1712.     inline void AddArgument(AstExpression *);
  1713.  
  1714.     inline AstExpression *&LocalArgument(int i) { return (*local_arguments_opt)[i]; }
  1715.     inline int NumLocalArguments() { return (local_arguments_opt ? local_arguments_opt -> Length() : 0); }
  1716.     inline void AllocateLocalArguments(int estimate = 0);
  1717.     inline void AddLocalArgument(AstExpression *);
  1718.  
  1719.     inline void AddNullArgument() { add_null_argument = true; }
  1720.     inline bool NeedsExtraNullArgument() { return add_null_argument; }
  1721.  
  1722. #ifdef TEST
  1723.     virtual void Print(LexStream &);
  1724. #endif
  1725.  
  1726.     virtual Ast *Clone(StoragePool *);
  1727.  
  1728.     virtual LexStream::TokenIndex LeftToken() { return (base_opt ? base_opt -> LeftToken() : super_token); }
  1729.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  1730. };
  1731.  
  1732.  
  1733. //
  1734. // ConstructorDeclaration --> <CONSTRUCTOR, Constructormodifiers, MethodDeclarator, Throws, ConstructorBody>
  1735. //
  1736. // ConstructorBody --> <CONSTRUCTOR_BLOCK, {_token, ExplicitConstructorInvocation, BlockStatements, }_token>
  1737. //                   | MethodBody
  1738. //
  1739. // ConstructorModifier --> Modifier (PUBLIC, PROTECTED or PRIVATE)
  1740. //
  1741. // ExplicitConstructorInvocation --> ThisCall
  1742. //                                 | SuperCall
  1743. //
  1744. class AstConstructorBlock : public AstStatement
  1745. {
  1746. private:
  1747.  
  1748.     StoragePool *pool;
  1749.     AstArray<AstStatement *> *local_init_statements;
  1750.  
  1751. public:
  1752.     BlockSymbol *block_symbol;
  1753.  
  1754.     LexStream::TokenIndex left_brace_token;
  1755.     Ast *explicit_constructor_invocation_opt;
  1756.     AstBlock *block;
  1757.     LexStream::TokenIndex right_brace_token;
  1758.  
  1759.     AstExpressionStatement *original_constructor_invocation;
  1760.  
  1761.     AstConstructorBlock(StoragePool *pool_) : pool(pool_),
  1762.                                               local_init_statements(NULL),
  1763.                                               block_symbol(NULL),
  1764.                                               original_constructor_invocation(NULL)
  1765.     {
  1766.         Ast::kind = Ast::CONSTRUCTOR_BLOCK;
  1767.         Ast::class_tag = Ast::STATEMENT;
  1768.         Ast::generated = 0;
  1769.         AstStatement::is_reachable = false;
  1770.         AstStatement::can_complete_normally = false;
  1771.     }
  1772.  
  1773.     virtual ~AstConstructorBlock();
  1774.  
  1775.     inline AstStatement *&LocalInitStatement(int i) { return (*local_init_statements)[i]; }
  1776.     inline int NumLocalInitStatements() { return (local_init_statements ? local_init_statements -> Length() : 0); }
  1777.     inline void AllocateLocalInitStatements(int estimate = 0);
  1778.     inline void AddLocalInitStatement(AstStatement *);
  1779.  
  1780. #ifdef TEST
  1781.     virtual void Print(LexStream &);
  1782. #endif
  1783.  
  1784.     virtual Ast *Clone(StoragePool *);
  1785.  
  1786.     virtual LexStream::TokenIndex LeftToken()  { return left_brace_token;  }
  1787.     virtual LexStream::TokenIndex RightToken() { return right_brace_token; }
  1788. };
  1789.  
  1790.  
  1791. class AstConstructorDeclaration : public Ast
  1792. {
  1793.     StoragePool *pool;
  1794.     AstArray<AstModifier *> *constructor_modifiers;
  1795.     AstArray<AstExpression *> *throws;
  1796.  
  1797. public:
  1798.     MethodSymbol *constructor_symbol;
  1799.     int index;
  1800.  
  1801.     AstMethodDeclarator *constructor_declarator;
  1802.     AstConstructorBlock *constructor_body;
  1803.  
  1804.     AstConstructorDeclaration(StoragePool *pool_) : pool(pool_),
  1805.                                                     throws(NULL),
  1806.                                                     constructor_modifiers(NULL),
  1807.                                                     constructor_symbol(NULL),
  1808.                                                     index(CycleChecker::OMEGA)
  1809.     {
  1810.         Ast::kind = Ast::CONSTRUCTOR;
  1811.         Ast::class_tag = Ast::NO_TAG;
  1812.         Ast::generated = 0;
  1813.     }
  1814.  
  1815.     virtual ~AstConstructorDeclaration();
  1816.  
  1817.     bool IsValid() { return constructor_symbol != NULL; }
  1818.  
  1819.     inline AstModifier *&ConstructorModifier(int i) { return (*constructor_modifiers)[i]; }
  1820.     inline int NumConstructorModifiers() { return (constructor_modifiers ? constructor_modifiers -> Length() : 0); }
  1821.     inline void AllocateConstructorModifiers(int estimate = 0);
  1822.     inline void AddConstructorModifier(AstModifier *);
  1823.  
  1824.     inline AstExpression *&Throw(int i) { return (*throws)[i]; }
  1825.     inline int NumThrows() { return (throws ? throws -> Length() : 0); }
  1826.     inline void AllocateThrows(int estimate = 0);
  1827.     inline void AddThrow(AstExpression *);
  1828.  
  1829. #ifdef TEST
  1830.     virtual void Print(LexStream &);
  1831. #endif
  1832.  
  1833.     virtual Ast *Clone(StoragePool *);
  1834.  
  1835.     virtual LexStream::TokenIndex LeftToken()
  1836.     {
  1837.         return (NumConstructorModifiers() > 0 ? (*constructor_modifiers)[0] -> LeftToken() : constructor_declarator -> LeftToken());
  1838.     }
  1839.     virtual LexStream::TokenIndex RightToken() { return constructor_body -> RightToken(); }
  1840. };
  1841.  
  1842.  
  1843. //
  1844. // InterfaceDeclaration --> <INTERFACE, Interfacemodifiers, interface_token, identifier_token, ExtendsInterfaces, {_token, InterfaceMemberDeclarations, }_token>
  1845. //
  1846. // InterfaceModifier --> Modifier (PUBLIC, ABSTRACT)
  1847. //
  1848. // ExtendsInterfaces --> Names
  1849. //
  1850. //
  1851. // InterfaceMemberDeclaration --> ConstantDeclaration
  1852. //                              | AbstractMethodDeclaration
  1853. //
  1854. // ConstantDeclaration --> FieldDeclaration (where the FieldModifierList is a Constantmodifiers)
  1855. //
  1856. // ConstantModifier --> Modifier (PUBLIC, STATIC or FINAL)
  1857. //
  1858. // AbstractMethodDeclaration --> MethodDeclaration (where MethodModifierList is a SignatureModifierList and the
  1859. //                                                  MethodBody is an EmptyStatement)
  1860. //
  1861. // SignatureModifier --> Modifier (PUBLIC or ABSTRACT)
  1862. //
  1863. class AstInterfaceDeclaration : public Ast
  1864. {
  1865. private:
  1866.     friend class Parser;
  1867.  
  1868.     StoragePool *pool;
  1869.     AstArray<AstModifier *> *interface_modifiers;
  1870.     AstArray<AstExpression *> *extends_interfaces;
  1871.     AstArray<Ast *> *interface_member_declarations;
  1872.  
  1873.     AstArray<AstFieldDeclaration *> *class_variables;
  1874.     AstArray<AstMethodDeclaration *> *methods;
  1875.     AstArray<AstClassDeclaration *> *inner_classes;
  1876.     AstArray<AstInterfaceDeclaration *> *inner_interfaces;
  1877.     AstArray<AstEmptyDeclaration *> *empty_declarations;
  1878.  
  1879. public:
  1880.  
  1881.     SemanticEnvironment *semantic_environment;
  1882.  
  1883.     LexStream::TokenIndex interface_token;
  1884.     LexStream::TokenIndex identifier_token;
  1885.     LexStream::TokenIndex left_brace_token;
  1886.     LexStream::TokenIndex right_brace_token;
  1887.  
  1888.     inline void mark_unparsed() { Ast::class_tag = Ast::UNPARSED; }
  1889.     inline void mark_parsed()   { Ast::class_tag = Ast::NO_TAG; }
  1890.  
  1891.     AstInterfaceDeclaration(StoragePool *pool_) : pool(pool_),
  1892.                                                   interface_modifiers(NULL),
  1893.                                                   extends_interfaces(NULL),
  1894.                                                   interface_member_declarations(NULL),
  1895.                                                   semantic_environment(NULL),
  1896.                                                   class_variables(NULL),
  1897.                                                   methods(NULL),
  1898.                                                   inner_classes(NULL),
  1899.                                                   inner_interfaces(NULL),
  1900.                                                   empty_declarations(NULL)
  1901.     {
  1902.         Ast::kind = Ast::INTERFACE;
  1903.         Ast::class_tag = Ast::NO_TAG;
  1904.         Ast::generated = 0;
  1905.     }
  1906.  
  1907.     virtual ~AstInterfaceDeclaration();
  1908.  
  1909.     bool IsValid() { return semantic_environment != NULL; }
  1910.  
  1911.     inline AstModifier *&InterfaceModifier(int i) { return (*interface_modifiers)[i]; }
  1912.     inline int NumInterfaceModifiers() { return (interface_modifiers ? interface_modifiers -> Length() : 0); }
  1913.     inline void AllocateInterfaceModifiers(int estimate = 0);
  1914.     inline void AddInterfaceModifier(AstModifier *);
  1915.  
  1916.     inline AstExpression *&ExtendsInterface(int i) { return (*extends_interfaces)[i]; }
  1917.     inline int NumExtendsInterfaces() { return (extends_interfaces ? extends_interfaces -> Length() : 0); }
  1918.     inline void AllocateExtendsInterfaces(int estimate = 0);
  1919.     inline void AddExtendsInterface(AstExpression *);
  1920.  
  1921.     inline Ast *&InterfaceMemberDeclaration(int i) { return (*interface_member_declarations)[i]; }
  1922.     inline int NumInterfaceMemberDeclarations()
  1923.                { return (interface_member_declarations ? interface_member_declarations -> Length() : 0); }
  1924.     inline void AllocateInterfaceMemberDeclarations(int estimate = 0);
  1925.     inline void AddInterfaceMemberDeclaration(Ast *);
  1926.  
  1927.     inline AstFieldDeclaration *&ClassVariable(int i) { return (*class_variables)[i]; }
  1928.     inline int NumClassVariables() { return (class_variables ? class_variables -> Length() : 0); }
  1929.     inline void AllocateClassVariables(int estimate = 0);
  1930.     inline void AddClassVariable(AstFieldDeclaration *);
  1931.  
  1932.     inline AstMethodDeclaration *&Method(int i) { return (*methods)[i]; }
  1933.     inline int NumMethods() { return (methods ? methods -> Length() : 0); }
  1934.     inline void AllocateMethods(int estimate = 0);
  1935.     inline void AddMethod(AstMethodDeclaration *);
  1936.  
  1937.     inline AstClassDeclaration *&NestedClass(int i) { return (*inner_classes)[i]; }
  1938.     inline int NumNestedClasses() { return (inner_classes ? inner_classes -> Length() : 0); }
  1939.     inline void AllocateNestedClasses(int estimate = 0);
  1940.     inline void AddNestedClass(AstClassDeclaration *);
  1941.  
  1942.     inline AstInterfaceDeclaration *&NestedInterface(int i) { return (*inner_interfaces)[i]; }
  1943.     inline int NumNestedInterfaces() { return (inner_interfaces ? inner_interfaces -> Length() : 0); }
  1944.     inline void AllocateNestedInterfaces(int estimate = 0);
  1945.     inline void AddNestedInterface(AstInterfaceDeclaration *);
  1946.  
  1947.     inline AstEmptyDeclaration *&EmptyDeclaration(int i) { return (*empty_declarations)[i]; }
  1948.     inline int NumEmptyDeclarations() { return (empty_declarations ? empty_declarations -> Length() : 0); }
  1949.     inline void AllocateEmptyDeclarations(int estimate = 0);
  1950.     inline void AddEmptyDeclaration(AstEmptyDeclaration *);
  1951.  
  1952. #ifdef TEST
  1953.     virtual void Print(LexStream &);
  1954. #endif
  1955.  
  1956.     virtual Ast *Clone(StoragePool *);
  1957.  
  1958.     virtual LexStream::TokenIndex LeftToken()
  1959.     {
  1960.         return (NumInterfaceModifiers() > 0 ? (*interface_modifiers)[0] -> LeftToken() : interface_token);
  1961.     }
  1962.     virtual LexStream::TokenIndex RightToken() { return right_brace_token; }
  1963. };
  1964.  
  1965.  
  1966. //
  1967. // LocalVariableDeclarationStatement --> <LOCAL_VARIABLE_DECLARATION, Type, VariableDeclarators, ;_token_opt>
  1968. //
  1969. class AstLocalVariableDeclarationStatement : public AstStatement
  1970. {
  1971.     StoragePool *pool;
  1972.     AstArray<AstModifier *> *local_modifiers;
  1973.     AstArray<AstVariableDeclarator *> *variable_declarators;
  1974.  
  1975. public:
  1976.     Ast *type;
  1977.     LexStream::TokenIndex semicolon_token_opt;
  1978.  
  1979.     AstLocalVariableDeclarationStatement(StoragePool *pool_) : pool(pool_),
  1980.                                                                local_modifiers(NULL),
  1981.                                                                variable_declarators(NULL)
  1982.     {
  1983.         Ast::kind = Ast::LOCAL_VARIABLE_DECLARATION;
  1984.         Ast::class_tag = Ast::STATEMENT;
  1985.         Ast::generated = 0;
  1986.         AstStatement::is_reachable = false;
  1987.         AstStatement::can_complete_normally = false;
  1988.     }
  1989.  
  1990.     virtual ~AstLocalVariableDeclarationStatement();
  1991.  
  1992.     inline AstModifier *&LocalModifier(int i) { return (*local_modifiers)[i]; }
  1993.     inline int NumLocalModifiers() { return (local_modifiers ? local_modifiers -> Length() : 0); }
  1994.     inline void AllocateLocalModifiers(int estimate = 0);
  1995.     inline void AddLocalModifier(AstModifier *);
  1996.  
  1997.     inline AstVariableDeclarator *&VariableDeclarator(int i) { return (*variable_declarators)[i]; }
  1998.     inline int NumVariableDeclarators() { return (variable_declarators ? variable_declarators -> Length() : 0); }
  1999.     inline void AllocateVariableDeclarators(int estimate = 0);
  2000.     inline void AddVariableDeclarator(AstVariableDeclarator *);
  2001.  
  2002. #ifdef TEST
  2003.     virtual void Print(LexStream &);
  2004. #endif
  2005.  
  2006.     virtual Ast *Clone(StoragePool *);
  2007.  
  2008.     virtual LexStream::TokenIndex LeftToken()
  2009.     {
  2010.         return (NumLocalModifiers() > 0 ? (*local_modifiers)[0] -> LeftToken() : type -> LeftToken());
  2011.     }
  2012.     virtual LexStream::TokenIndex RightToken()
  2013.     {
  2014.         return (semicolon_token_opt ? semicolon_token_opt : VariableDeclarator(NumVariableDeclarators() - 1) -> RightToken());
  2015.     }
  2016. };
  2017.  
  2018. //
  2019. // Statement --> IfStatement
  2020. //             | WhileStatement
  2021. //             | ForStatement
  2022. //             | Block
  2023. //             | EmptyStatement
  2024. //             | ExpressionStatement
  2025. //             | SwitchStatement
  2026. //             | DoStatement
  2027. //             | BreakStatement
  2028. //             | ContinueStatement
  2029. //             | ReturnStatement
  2030. //             | SynchronizedStatement
  2031. //             | ThrowStatement
  2032. //             | TryStatement
  2033. //
  2034. // Label --> identifier_token
  2035. //
  2036. // IfStatement --> <IF, Label_opt, if_token, Expression, TrueStatement, FalseStatement_opt>
  2037. //
  2038. // TrueStatement --> Statement
  2039. //
  2040. // FalseStatement --> Statement
  2041. //
  2042. class AstIfStatement : public AstStatement
  2043. {
  2044. public:
  2045.     LexStream::TokenIndex if_token;
  2046.     AstExpression *expression;
  2047.     AstStatement *true_statement;
  2048.     AstStatement *false_statement_opt;
  2049.  
  2050.     AstIfStatement() : expression(NULL)
  2051.     {
  2052.         Ast::kind = Ast::IF;
  2053.         Ast::class_tag = Ast::STATEMENT;
  2054.         Ast::generated = 0;
  2055.         AstStatement::is_reachable = false;
  2056.         AstStatement::can_complete_normally = false;
  2057.     }
  2058.  
  2059.     virtual ~AstIfStatement();
  2060.  
  2061. #ifdef TEST
  2062.     virtual void Print(LexStream &);
  2063. #endif
  2064.  
  2065.     virtual Ast *Clone(StoragePool *);
  2066.  
  2067.     virtual LexStream::TokenIndex LeftToken()
  2068.     {
  2069.         return if_token;
  2070.     }
  2071.     virtual LexStream::TokenIndex RightToken()
  2072.     {
  2073.         return (false_statement_opt ? false_statement_opt -> RightToken()
  2074.                                     : true_statement -> RightToken());
  2075.     }
  2076. };
  2077.  
  2078.  
  2079. //
  2080. // EmptyStatement --> <EMPTY_STATEMENT, Label_opt, ;_token>
  2081. //
  2082. class AstEmptyStatement : public AstStatement
  2083. {
  2084. public:
  2085.     LexStream::TokenIndex semicolon_token;
  2086.  
  2087.     AstEmptyStatement(LexStream::TokenIndex token_) : semicolon_token(token_)
  2088.     {
  2089.         Ast::kind = Ast::EMPTY_STATEMENT;
  2090.         Ast::class_tag = Ast::STATEMENT;
  2091.         Ast::generated = 0;
  2092.         AstStatement::is_reachable = false;
  2093.         AstStatement::can_complete_normally = false;
  2094.     }
  2095.  
  2096.     virtual ~AstEmptyStatement();
  2097.  
  2098. #ifdef TEST
  2099.     virtual void Print(LexStream &);
  2100. #endif
  2101.  
  2102.     virtual Ast *Clone(StoragePool *);
  2103.  
  2104.     virtual LexStream::TokenIndex LeftToken()
  2105.     {
  2106.         return semicolon_token;
  2107.     }
  2108.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  2109. };
  2110.  
  2111.  
  2112. //
  2113. // ExpressionStatement --> <EXPRESSION_STATEMENT, Label_opt, Expression, ;_token_opt>
  2114. //
  2115. class AstExpressionStatement : public AstStatement
  2116. {
  2117. public:
  2118.     AstExpression *expression;
  2119.     LexStream::TokenIndex semicolon_token_opt;
  2120.  
  2121.     AstExpressionStatement()
  2122.     {
  2123.         Ast::kind = Ast::EXPRESSION_STATEMENT;
  2124.         Ast::class_tag = Ast::STATEMENT;
  2125.         Ast::generated = 0;
  2126.         AstStatement::is_reachable = false;
  2127.         AstStatement::can_complete_normally = false;
  2128.     }
  2129.  
  2130.     virtual ~AstExpressionStatement();
  2131.  
  2132. #ifdef TEST
  2133.     virtual void Print(LexStream &);
  2134. #endif
  2135.  
  2136.     virtual Ast *Clone(StoragePool *);
  2137.  
  2138.     virtual LexStream::TokenIndex LeftToken()
  2139.     {
  2140.         return expression -> LeftToken();
  2141.     }
  2142.     virtual LexStream::TokenIndex RightToken()
  2143.     {
  2144.         return (semicolon_token_opt ? semicolon_token_opt : expression -> RightToken());
  2145.     }
  2146. };
  2147.  
  2148.  
  2149. //
  2150. // SwitchLabel --> CaseLabel
  2151. //               | DefaultLabel
  2152. //
  2153. // CaseLabel --> <CASE, case_token, Expression, :_token>
  2154. //
  2155. class AstCaseLabel : public Ast
  2156. {
  2157. public:
  2158.     LexStream::TokenIndex case_token;
  2159.     AstExpression *expression;
  2160.     LexStream::TokenIndex colon_token;
  2161.     int map_index;
  2162.  
  2163.     AstCaseLabel()
  2164.     {
  2165.         Ast::kind = Ast::CASE;
  2166.         Ast::class_tag = Ast::NO_TAG;
  2167.         Ast::generated = 0;
  2168.     }
  2169.  
  2170.     virtual ~AstCaseLabel();
  2171.  
  2172. #ifdef TEST
  2173.     virtual void Print(LexStream &);
  2174. #endif
  2175.  
  2176.     virtual Ast *Clone(StoragePool *);
  2177.  
  2178.     virtual LexStream::TokenIndex LeftToken() { return case_token; }
  2179.     virtual LexStream::TokenIndex RightToken() { return colon_token; }
  2180. };
  2181.  
  2182.  
  2183. //
  2184. // DefaultLabel --> <DEFAULT, default_token, :_token>
  2185. //
  2186. class AstDefaultLabel : public Ast
  2187. {
  2188. public:
  2189.     LexStream::TokenIndex default_token;
  2190.     LexStream::TokenIndex colon_token;
  2191.  
  2192.     AstDefaultLabel()
  2193.     {
  2194.         Ast::kind = Ast::DEFAULT;
  2195.         Ast::class_tag = Ast::NO_TAG;
  2196.         Ast::generated = 0;
  2197.     }
  2198.  
  2199.     virtual ~AstDefaultLabel();
  2200.  
  2201. #ifdef TEST
  2202.     virtual void Print(LexStream &);
  2203. #endif
  2204.  
  2205.     virtual Ast *Clone(StoragePool *);
  2206.  
  2207.     virtual LexStream::TokenIndex LeftToken() { return default_token; }
  2208.     virtual LexStream::TokenIndex RightToken() { return colon_token; }
  2209. };
  2210.  
  2211.  
  2212. //
  2213. // SwitchBlockStatement --> <SWITCH_BLOCK, SwitchLabels, BlockStatements>
  2214. //
  2215. class AstSwitchBlockStatement : public Ast
  2216. {
  2217. private:
  2218.     StoragePool *pool;
  2219.  
  2220.     AstArray<AstStatement *> *block_statements;
  2221.     AstArray<Ast *> *switch_labels;
  2222.  
  2223. public:
  2224.  
  2225.     AstSwitchBlockStatement(StoragePool *pool_) : pool(pool_),
  2226.                                                   block_statements(NULL),
  2227.                                                   switch_labels(NULL)
  2228.     {
  2229.         Ast::kind = Ast::SWITCH_BLOCK;
  2230.         Ast::class_tag = Ast::NO_TAG;
  2231.         Ast::generated = 0;
  2232.     }
  2233.  
  2234.     virtual ~AstSwitchBlockStatement();
  2235.  
  2236.     inline AstStatement *&Statement(int i) { return (*block_statements)[i]; }
  2237.     inline int NumStatements() { return (block_statements ? block_statements -> Length() : 0); }
  2238.     inline void AllocateBlockStatements(int estimate = 0);
  2239.     inline void AddStatement(AstStatement *);
  2240.  
  2241.     inline Ast *&SwitchLabel(int i) { return (*switch_labels)[i]; }
  2242.     inline int NumSwitchLabels() { return (switch_labels ? switch_labels -> Length() : 0); }
  2243.     inline void AllocateSwitchLabels(int estimate = 0);
  2244.     inline void AddSwitchLabel(Ast *);
  2245.  
  2246. #ifdef TEST
  2247.     virtual void Print(LexStream &);
  2248. #endif
  2249.  
  2250.     virtual Ast *Clone(StoragePool *);
  2251.  
  2252.     virtual LexStream::TokenIndex LeftToken()
  2253.     {
  2254.         return SwitchLabel(0) -> LeftToken();
  2255.     }
  2256.     virtual LexStream::TokenIndex RightToken()
  2257.     {
  2258.         return Statement(NumStatements() - 1) -> RightToken();
  2259.     }
  2260. };
  2261.  
  2262.  
  2263. class CaseElement
  2264. {
  2265. public:
  2266.     AstSwitchBlockStatement *switch_block_statement;
  2267.     AstExpression *expression;
  2268.     int index;
  2269.  
  2270.     int Value() { return ((IntLiteralValue *) (expression -> value)) -> value; }
  2271.  
  2272.     inline AstStatement *&Statement(int i) { return switch_block_statement -> Statement(i); }
  2273.     inline int NumStatements() { return switch_block_statement -> NumStatements(); }
  2274. };
  2275.  
  2276. //
  2277. // SwitchStatement --> <SWITCH, Label_opt, switch_token, Expression, {_token, SwitchBlockStatements, SwitchLabels_opt, }_token>
  2278. //
  2279. class AstSwitchStatement : public AstStatement
  2280. {
  2281.     StoragePool *pool;
  2282.     AstArray<CaseElement *> *cases;
  2283.  
  2284. public:
  2285.     CaseElement default_case;
  2286.  
  2287.     LexStream::TokenIndex switch_token;
  2288.     AstExpression *expression;
  2289.     AstBlock *switch_block;
  2290.  
  2291.     AstSwitchStatement(StoragePool *pool_) : pool(pool_),
  2292.                                              cases(NULL)
  2293.     {
  2294.         Ast::kind = Ast::SWITCH;
  2295.         Ast::class_tag = Ast::STATEMENT;
  2296.         Ast::generated = 0;
  2297.         AstStatement::is_reachable = false;
  2298.         AstStatement::can_complete_normally = false;
  2299.     }
  2300.  
  2301.     virtual ~AstSwitchStatement();
  2302.  
  2303.     inline CaseElement *&Case(int i) { return (*cases)[i]; }
  2304.     inline int NumCases() { return (cases ? cases -> Length() : 0); }
  2305.     inline void AllocateCases(int estimate = 0);
  2306.     inline void AddCase(CaseElement *);
  2307.  
  2308.     void SortCases();
  2309.  
  2310. #ifdef TEST
  2311.     virtual void Print(LexStream &);
  2312. #endif
  2313.  
  2314.     virtual Ast *Clone(StoragePool *);
  2315.  
  2316.     virtual LexStream::TokenIndex LeftToken()
  2317.     {
  2318.         return switch_token;
  2319.     }
  2320.     virtual LexStream::TokenIndex RightToken() { return switch_block -> RightToken(); }
  2321. };
  2322.  
  2323.  
  2324. //
  2325. // WhileStatement --> <WHILE, Label_opt, while_token, Expression, Statement>
  2326. //
  2327. class AstWhileStatement : public AstStatement
  2328. {
  2329. public:
  2330.     LexStream::TokenIndex while_token;
  2331.     AstExpression *expression;
  2332.     AstStatement *statement;
  2333.  
  2334.     AstWhileStatement()
  2335.     {
  2336.         Ast::kind = Ast::WHILE;
  2337.         Ast::class_tag = Ast::STATEMENT;
  2338.         Ast::generated = 0;
  2339.         AstStatement::is_reachable = false;
  2340.         AstStatement::can_complete_normally = false;
  2341.     }
  2342.  
  2343.     virtual ~AstWhileStatement();
  2344.  
  2345. #ifdef TEST
  2346.     virtual void Print(LexStream &);
  2347. #endif
  2348.  
  2349.     virtual Ast *Clone(StoragePool *);
  2350.  
  2351.     virtual LexStream::TokenIndex LeftToken()
  2352.     {
  2353.         return while_token;
  2354.     }
  2355.     virtual LexStream::TokenIndex RightToken() { return statement -> RightToken(); }
  2356. };
  2357.  
  2358.  
  2359. //
  2360. // DoStatement --> <DO, Label_opt, do_token, Expression, Statement, ;_token>
  2361. //
  2362. class AstDoStatement : public AstStatement
  2363. {
  2364. public:
  2365.     LexStream::TokenIndex do_token;
  2366.     AstStatement *statement;
  2367.     LexStream::TokenIndex while_token;
  2368.     AstExpression *expression;
  2369.     LexStream::TokenIndex semicolon_token;
  2370.  
  2371.     AstDoStatement()
  2372.     {
  2373.         Ast::kind = Ast::DO;
  2374.         Ast::class_tag = Ast::STATEMENT;
  2375.         Ast::generated = 0;
  2376.         AstStatement::is_reachable = false;
  2377.         AstStatement::can_complete_normally = false;
  2378.     }
  2379.  
  2380.     virtual ~AstDoStatement();
  2381.  
  2382. #ifdef TEST
  2383.     virtual void Print(LexStream &);
  2384. #endif
  2385.  
  2386.     virtual Ast *Clone(StoragePool *);
  2387.  
  2388.     virtual LexStream::TokenIndex LeftToken()
  2389.     {
  2390.         return do_token;
  2391.     }
  2392.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  2393. };
  2394.  
  2395.  
  2396. //
  2397. // ForStatement --> <FOR, Label_opt, for_token, ForInits, Expression_opt, ForUpdates, Statement>
  2398. //
  2399. // ForInit --> ExpressionStatement
  2400. //           | LocalVariableDeclarationStatement
  2401. //
  2402. // ForUpdate --> ExpressionStatement
  2403. //
  2404. class AstForStatement : public AstStatement
  2405. {
  2406. private:
  2407.  
  2408.     StoragePool *pool;
  2409.     AstArray<AstStatement *> *for_init_statements;
  2410.     AstArray<AstExpressionStatement *> *for_update_statements;
  2411.  
  2412. public:
  2413.     LexStream::TokenIndex for_token;
  2414.     AstExpression *end_expression_opt;
  2415.     AstStatement *statement;
  2416.  
  2417.     AstForStatement(StoragePool *pool_) : pool(pool_),
  2418.                                           for_init_statements(NULL),
  2419.                                           for_update_statements(NULL)
  2420.     {
  2421.         Ast::kind = Ast::FOR;
  2422.         Ast::class_tag = Ast::STATEMENT;
  2423.         Ast::generated = 0;
  2424.         AstStatement::is_reachable = false;
  2425.         AstStatement::can_complete_normally = false;
  2426.     }
  2427.  
  2428.     virtual ~AstForStatement();
  2429.  
  2430.     inline AstStatement *&ForInitStatement(int i) { return (*for_init_statements)[i]; }
  2431.     inline int NumForInitStatements() { return (for_init_statements ? for_init_statements -> Length() : 0); }
  2432.     inline void AllocateForInitStatements(int estimate = 0);
  2433.     inline void AddForInitStatement(AstStatement *);
  2434.  
  2435.     inline AstExpressionStatement *&ForUpdateStatement(int i) { return (*for_update_statements)[i]; }
  2436.     inline int NumForUpdateStatements() { return (for_update_statements ? for_update_statements -> Length() : 0); }
  2437.     inline void AllocateForUpdateStatements(int estimate = 0);
  2438.     inline void AddForUpdateStatement(AstExpressionStatement *);
  2439.  
  2440. #ifdef TEST
  2441.     virtual void Print(LexStream &);
  2442. #endif
  2443.  
  2444.     virtual Ast *Clone(StoragePool *);
  2445.  
  2446.     virtual LexStream::TokenIndex LeftToken()
  2447.     {
  2448.         return for_token;
  2449.     }
  2450.     virtual LexStream::TokenIndex RightToken() { return statement -> RightToken(); }
  2451. };
  2452.  
  2453.  
  2454. //
  2455. // BreakStatement --> <BREAK, Label_opt, break_token, identifier_token_opt, ;_token>
  2456. //
  2457. class AstBreakStatement : public AstStatement
  2458. {
  2459. public:
  2460.     LexStream::TokenIndex break_token;
  2461.     LexStream::TokenIndex identifier_token_opt;
  2462.     LexStream::TokenIndex semicolon_token;
  2463.     int nesting_level;
  2464.  
  2465.     AstBreakStatement()
  2466.     {
  2467.         Ast::kind = Ast::BREAK;
  2468.         Ast::class_tag = Ast::STATEMENT;
  2469.         Ast::generated = 0;
  2470.         AstStatement::is_reachable = false;
  2471.         AstStatement::can_complete_normally = false;
  2472.     }
  2473.  
  2474.     virtual ~AstBreakStatement();
  2475.  
  2476. #ifdef TEST
  2477.     virtual void Print(LexStream &);
  2478. #endif
  2479.  
  2480.     virtual Ast *Clone(StoragePool *);
  2481.  
  2482.     virtual LexStream::TokenIndex LeftToken()
  2483.     {
  2484.         return break_token;
  2485.     }
  2486.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  2487. };
  2488.  
  2489. //
  2490. // ContinueStatement --> <CONTINUE, Label_opt, continue_token, SimpleName_opt, ;_token>
  2491. //
  2492. class AstContinueStatement : public AstStatement
  2493. {
  2494. public:
  2495.     LexStream::TokenIndex continue_token;
  2496.     LexStream::TokenIndex identifier_token_opt;
  2497.     LexStream::TokenIndex semicolon_token;
  2498.     int nesting_level;
  2499.  
  2500.     AstContinueStatement()
  2501.     {
  2502.         Ast::kind = Ast::CONTINUE;
  2503.         Ast::class_tag = Ast::STATEMENT;
  2504.         Ast::generated = 0;
  2505.         AstStatement::is_reachable = false;
  2506.         AstStatement::can_complete_normally = false;
  2507.     }
  2508.  
  2509.     virtual ~AstContinueStatement();
  2510.  
  2511. #ifdef TEST
  2512.     virtual void Print(LexStream &);
  2513. #endif
  2514.  
  2515.     virtual Ast *Clone(StoragePool *);
  2516.  
  2517.     virtual LexStream::TokenIndex LeftToken()
  2518.     {
  2519.         return continue_token;
  2520.     }
  2521.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  2522. };
  2523.  
  2524.  
  2525. //
  2526. // ReturnStatement --> <RETURN, Label_opt, return_token, Expression_opt, ;_token>
  2527. //
  2528. class AstReturnStatement : public AstStatement
  2529. {
  2530. public:
  2531.     LexStream::TokenIndex return_token;
  2532.     AstExpression *expression_opt;
  2533.     LexStream::TokenIndex semicolon_token;
  2534.  
  2535.     AstReturnStatement()
  2536.     {
  2537.         Ast::kind = Ast::RETURN;
  2538.         Ast::class_tag = Ast::STATEMENT;
  2539.         Ast::generated = 0;
  2540.         AstStatement::is_reachable = false;
  2541.         AstStatement::can_complete_normally = false;
  2542.     }
  2543.  
  2544.     virtual ~AstReturnStatement();
  2545.  
  2546. #ifdef TEST
  2547.     virtual void Print(LexStream &);
  2548. #endif
  2549.  
  2550.     virtual Ast *Clone(StoragePool *);
  2551.  
  2552.     virtual LexStream::TokenIndex LeftToken()
  2553.     {
  2554.         return return_token;
  2555.     }
  2556.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  2557. };
  2558.  
  2559.  
  2560. //
  2561. // ThrowStatement --> <THROW, Label_opt, throw_token, Expression, ;_token>
  2562. //
  2563. class AstThrowStatement : public AstStatement
  2564. {
  2565. public:
  2566.     LexStream::TokenIndex throw_token;
  2567.     AstExpression *expression;
  2568.     LexStream::TokenIndex semicolon_token;
  2569.  
  2570.     AstThrowStatement()
  2571.     {
  2572.         Ast::kind = Ast::THROW;
  2573.         Ast::class_tag = Ast::STATEMENT;
  2574.         Ast::generated = 0;
  2575.         AstStatement::is_reachable = false;
  2576.         AstStatement::can_complete_normally = false;
  2577.     }
  2578.  
  2579.     virtual ~AstThrowStatement();
  2580.  
  2581. #ifdef TEST
  2582.     virtual void Print(LexStream &);
  2583. #endif
  2584.  
  2585.     virtual Ast *Clone(StoragePool *);
  2586.  
  2587.     virtual LexStream::TokenIndex LeftToken()
  2588.     {
  2589.         return throw_token;
  2590.     }
  2591.     virtual LexStream::TokenIndex RightToken() { return semicolon_token; }
  2592. };
  2593.  
  2594.  
  2595. //
  2596. // SynchronizedStatement --> <SYNCHRONIZED_STATEMENT, Label_opt, synchronized_token, Expression, Block>
  2597. //
  2598. class AstSynchronizedStatement : public AstStatement
  2599. {
  2600. public:
  2601.     LexStream::TokenIndex synchronized_token;
  2602.     AstExpression *expression;
  2603.     AstBlock *block;
  2604.  
  2605.     AstSynchronizedStatement()
  2606.     {
  2607.         Ast::kind = Ast::SYNCHRONIZED_STATEMENT;
  2608.         Ast::class_tag = Ast::STATEMENT;
  2609.         Ast::generated = 0;
  2610.         AstStatement::is_reachable = false;
  2611.         AstStatement::can_complete_normally = false;
  2612.     }
  2613.  
  2614.     virtual ~AstSynchronizedStatement();
  2615.  
  2616. #ifdef TEST
  2617.     virtual void Print(LexStream &);
  2618. #endif
  2619.  
  2620.     virtual Ast *Clone(StoragePool *);
  2621.  
  2622.     virtual LexStream::TokenIndex LeftToken()
  2623.     {
  2624.         return synchronized_token;
  2625.     }
  2626.     virtual LexStream::TokenIndex RightToken() { return block -> RightToken(); }
  2627. };
  2628.  
  2629.  
  2630. //
  2631. // CatchClause --> <CATCH, catch_token, FormalParameter, Block>
  2632. //
  2633. class AstCatchClause : public Ast
  2634. {
  2635. public:
  2636.     VariableSymbol *parameter_symbol;
  2637.  
  2638.     LexStream::TokenIndex catch_token;
  2639.     AstFormalParameter *formal_parameter;
  2640.     AstBlock *block;
  2641.  
  2642.     AstCatchClause() : parameter_symbol(NULL)
  2643.     {
  2644.         Ast::kind = Ast::CATCH;
  2645.         Ast::class_tag = Ast::NO_TAG;
  2646.         Ast::generated = 0;
  2647.     }
  2648.  
  2649.     virtual ~AstCatchClause();
  2650.  
  2651. #ifdef TEST
  2652.     virtual void Print(LexStream &);
  2653. #endif
  2654.  
  2655.     virtual Ast *Clone(StoragePool *);
  2656.  
  2657.     virtual LexStream::TokenIndex LeftToken() { return catch_token; }
  2658.     virtual LexStream::TokenIndex RightToken() { return block -> RightToken(); }
  2659. };
  2660.  
  2661.  
  2662. //
  2663. // FinallyClause --> <FINALLY, finally_token, Block>
  2664. //
  2665. class AstFinallyClause : public Ast
  2666. {
  2667. public:
  2668.     LexStream::TokenIndex finally_token;
  2669.     AstBlock *block;
  2670.  
  2671.     AstFinallyClause()
  2672.     {
  2673.         Ast::kind = Ast::FINALLY;
  2674.         Ast::class_tag = Ast::NO_TAG;
  2675.         Ast::generated = 0;
  2676.     }
  2677.  
  2678.     virtual ~AstFinallyClause();
  2679.  
  2680. #ifdef TEST
  2681.     virtual void Print(LexStream &);
  2682. #endif
  2683.  
  2684.     virtual Ast *Clone(StoragePool *);
  2685.  
  2686.     virtual LexStream::TokenIndex LeftToken() { return finally_token; }
  2687.     virtual LexStream::TokenIndex RightToken() { return block -> RightToken(); }
  2688. };
  2689.  
  2690.  
  2691. //
  2692. // TryStatement --> <TRY, Label_opt, try-token, Block CatchClauses, FinallyClause_opt>
  2693. //
  2694. class AstTryStatement : public AstStatement
  2695. {
  2696. private:
  2697.  
  2698.     StoragePool *pool;
  2699.     AstArray<AstCatchClause *> *catch_clauses;
  2700.  
  2701. public:
  2702.     LexStream::TokenIndex try_token;
  2703.     AstBlock *block;
  2704.     AstFinallyClause *finally_clause_opt;
  2705.  
  2706.     AstTryStatement(StoragePool *pool_) : pool(pool_),
  2707.                                           catch_clauses(NULL)
  2708.     {
  2709.         Ast::kind = Ast::TRY;
  2710.         Ast::class_tag = Ast::STATEMENT;
  2711.         Ast::generated = 0;
  2712.         AstStatement::is_reachable = false;
  2713.         AstStatement::can_complete_normally = false;
  2714.     }
  2715.  
  2716.     virtual ~AstTryStatement();
  2717.  
  2718.     inline AstCatchClause *&CatchClause(int i) { return (*catch_clauses)[i]; }
  2719.     inline int NumCatchClauses() { return (catch_clauses ? catch_clauses -> Length() : 0); }
  2720.     inline void AllocateCatchClauses(int estimate = 0);
  2721.     inline void AddCatchClause(AstCatchClause *);
  2722.  
  2723. #ifdef TEST
  2724.     virtual void Print(LexStream &);
  2725. #endif
  2726.  
  2727.     virtual Ast *Clone(StoragePool *);
  2728.  
  2729.     virtual LexStream::TokenIndex LeftToken()
  2730.     {
  2731.         return try_token;
  2732.     }
  2733.     virtual LexStream::TokenIndex RightToken()
  2734.     {
  2735.         //
  2736.         // when the Finally clause is null, there must be one or more catch clauses
  2737.         //
  2738.         return (finally_clause_opt ? finally_clause_opt -> RightToken() : CatchClause(NumCatchClauses() - 1) -> RightToken());
  2739.     }
  2740. };
  2741.  
  2742. //
  2743. // Expression --> Primary
  2744. //              | UnaryExpression
  2745. //              | BinaryExpression
  2746. //              | ConditionalExpression
  2747. //              | AssignmentExpression
  2748. //
  2749. // Primary --> Literal
  2750. //           | NullLiteral
  2751. //           | ThisExpression
  2752. //           | SuperExpression
  2753. //           | ParenthesizedExpression
  2754. //           | ClassInstanceCreationExpression
  2755. //           | ArrayCreationExpression
  2756. //           | FieldAccess
  2757. //           | MethodInvocation
  2758. //           | ArrayAccess
  2759. //
  2760. // Literal --> IntegerLiteral
  2761. //           | LongLiteral
  2762. //           | FloatingPointLiteral
  2763. //           | DoubleLiteral
  2764. //           | BooleanLiteral
  2765. //           | StringLiteral
  2766. //           | CharacterLiteral
  2767. //
  2768. // BooleanLiteral --> TrueLiteral
  2769. //                  | FalseLiteral
  2770. //
  2771.  
  2772. //
  2773. // IntegerLiteral --> <INTEGER_LITERAL, integer_literal_token, value>
  2774. //
  2775. class AstIntegerLiteral : public AstExpression
  2776. {
  2777. public:
  2778.     LexStream::TokenIndex integer_literal_token;
  2779.  
  2780.     AstIntegerLiteral(LexStream::TokenIndex token_) : integer_literal_token(token_)
  2781.     {
  2782.         Ast::kind = Ast::INTEGER_LITERAL;
  2783.         Ast::class_tag = Ast::EXPRESSION;
  2784.         Ast::generated = 0;
  2785.         AstExpression::value = NULL;
  2786.         AstExpression::symbol = NULL;
  2787.     }
  2788.  
  2789.     virtual ~AstIntegerLiteral();
  2790.  
  2791. #ifdef TEST
  2792.     virtual void Print(LexStream &);
  2793. #endif
  2794.  
  2795.     virtual Ast *Clone(StoragePool *);
  2796.  
  2797.     virtual LexStream::TokenIndex LeftToken()  { return integer_literal_token; }
  2798.     virtual LexStream::TokenIndex RightToken() { return integer_literal_token; }
  2799. };
  2800.  
  2801.  
  2802. //
  2803. // LongLiteral --> <LONG_LITERAL, long_literal_token, value>
  2804. //
  2805. class AstLongLiteral : public AstExpression
  2806. {
  2807. public:
  2808.     LexStream::TokenIndex long_literal_token;
  2809.  
  2810.     AstLongLiteral(LexStream::TokenIndex token_) : long_literal_token(token_)
  2811.     {
  2812.         Ast::kind = Ast::LONG_LITERAL;
  2813.         Ast::class_tag = Ast::EXPRESSION;
  2814.         Ast::generated = 0;
  2815.         AstExpression::value = NULL;
  2816.         AstExpression::symbol = NULL;
  2817.     }
  2818.  
  2819.     virtual ~AstLongLiteral();
  2820.  
  2821. #ifdef TEST
  2822.     virtual void Print(LexStream &);
  2823. #endif
  2824.  
  2825.     virtual Ast *Clone(StoragePool *);
  2826.  
  2827.     virtual LexStream::TokenIndex LeftToken()  { return long_literal_token; }
  2828.     virtual LexStream::TokenIndex RightToken() { return long_literal_token; }
  2829. };
  2830.  
  2831.  
  2832. //
  2833. // FloatingPointLiteral --> <FLOATING_POINT_LITERAL, Literal, value>
  2834. //
  2835. class AstFloatingPointLiteral : public AstExpression
  2836. {
  2837. public:
  2838.     LexStream::TokenIndex floating_point_literal_token;
  2839.  
  2840.     AstFloatingPointLiteral(LexStream::TokenIndex token_) : floating_point_literal_token(token_)
  2841.     {
  2842.         Ast::kind = Ast::FLOATING_POINT_LITERAL;
  2843.         Ast::class_tag = Ast::EXPRESSION;
  2844.         Ast::generated = 0;
  2845.         AstExpression::value = NULL;
  2846.         AstExpression::symbol = NULL;
  2847.     }
  2848.  
  2849.     virtual ~AstFloatingPointLiteral();
  2850.  
  2851. #ifdef TEST
  2852.     virtual void Print(LexStream &);
  2853. #endif
  2854.  
  2855.     virtual Ast *Clone(StoragePool *);
  2856.  
  2857.     virtual LexStream::TokenIndex LeftToken()  { return floating_point_literal_token; }
  2858.     virtual LexStream::TokenIndex RightToken() { return floating_point_literal_token; }
  2859. };
  2860.  
  2861. //
  2862. // DoubleLiteral --> <DOUBLE_LITERAL, Literal, value>
  2863. //
  2864. class AstDoubleLiteral : public AstExpression
  2865. {
  2866. public:
  2867.     LexStream::TokenIndex double_literal_token;
  2868.  
  2869.     AstDoubleLiteral(LexStream::TokenIndex token_) : double_literal_token(token_)
  2870.     {
  2871.         Ast::kind = Ast::DOUBLE_LITERAL;
  2872.         Ast::class_tag = Ast::EXPRESSION;
  2873.         Ast::generated = 0;
  2874.         AstExpression::value = NULL;
  2875.         AstExpression::symbol = NULL;
  2876.     }
  2877.  
  2878.     virtual ~AstDoubleLiteral();
  2879.  
  2880. #ifdef TEST
  2881.     virtual void Print(LexStream &);
  2882. #endif
  2883.  
  2884.     virtual Ast *Clone(StoragePool *);
  2885.  
  2886.     virtual LexStream::TokenIndex LeftToken()  { return double_literal_token; }
  2887.     virtual LexStream::TokenIndex RightToken() { return double_literal_token; }
  2888. };
  2889.  
  2890. //
  2891. // TrueLiteral --> <TRUE_LITERAL, Literal, value>
  2892. //
  2893. class AstTrueLiteral : public AstExpression
  2894. {
  2895. public:
  2896.     LexStream::TokenIndex true_literal_token;
  2897.  
  2898.     AstTrueLiteral(LexStream::TokenIndex token_) : true_literal_token(token_)
  2899.     {
  2900.         Ast::kind = Ast::TRUE_LITERAL;
  2901.         Ast::class_tag = Ast::EXPRESSION;
  2902.         Ast::generated = 0;
  2903.         AstExpression::value = NULL;
  2904.         AstExpression::symbol = NULL;
  2905.     }
  2906.  
  2907.     virtual ~AstTrueLiteral();
  2908.  
  2909. #ifdef TEST
  2910.     virtual void Print(LexStream &);
  2911. #endif
  2912.  
  2913.     virtual Ast *Clone(StoragePool *);
  2914.  
  2915.     virtual LexStream::TokenIndex LeftToken()  { return true_literal_token; }
  2916.     virtual LexStream::TokenIndex RightToken() { return true_literal_token; }
  2917. };
  2918.  
  2919. //
  2920. // FalseLiteral --> <FALSE_LITERAL, Literal, value>
  2921. //
  2922. class AstFalseLiteral : public AstExpression
  2923. {
  2924. public:
  2925.     LexStream::TokenIndex false_literal_token;
  2926.  
  2927.     AstFalseLiteral(LexStream::TokenIndex token_) : false_literal_token(token_)
  2928.     {
  2929.         Ast::kind = Ast::FALSE_LITERAL;
  2930.         Ast::class_tag = Ast::EXPRESSION;
  2931.         Ast::generated = 0;
  2932.         AstExpression::value = NULL;
  2933.         AstExpression::symbol = NULL;
  2934.     }
  2935.  
  2936.     virtual ~AstFalseLiteral();
  2937.  
  2938. #ifdef TEST
  2939.     virtual void Print(LexStream &);
  2940. #endif
  2941.  
  2942.     virtual Ast *Clone(StoragePool *);
  2943.  
  2944.     virtual LexStream::TokenIndex LeftToken()  { return false_literal_token; }
  2945.     virtual LexStream::TokenIndex RightToken() { return false_literal_token; }
  2946. };
  2947.  
  2948. //
  2949. // StringLiteral --> <STRING_LITERAL, Literal, value>
  2950. //
  2951. class AstStringLiteral : public AstExpression
  2952. {
  2953. public:
  2954.     LexStream::TokenIndex string_literal_token;
  2955.  
  2956.     AstStringLiteral(LexStream::TokenIndex token_) : string_literal_token(token_)
  2957.     {
  2958.         Ast::kind = Ast::STRING_LITERAL;
  2959.         Ast::class_tag = Ast::EXPRESSION;
  2960.         Ast::generated = 0;
  2961.         AstExpression::value = NULL;
  2962.         AstExpression::symbol = NULL;
  2963.     }
  2964.  
  2965.     virtual ~AstStringLiteral();
  2966.  
  2967. #ifdef TEST
  2968.     virtual void Print(LexStream &);
  2969. #endif
  2970.  
  2971.     virtual Ast *Clone(StoragePool *);
  2972.  
  2973.     virtual LexStream::TokenIndex LeftToken()  { return string_literal_token; }
  2974.     virtual LexStream::TokenIndex RightToken() { return string_literal_token; }
  2975. };
  2976.  
  2977. //
  2978. // CharacterLiteral --> <CHARACTER_LITERAL, literal_token, value>
  2979. //
  2980. class AstCharacterLiteral : public AstExpression
  2981. {
  2982. public:
  2983.     LexStream::TokenIndex character_literal_token;
  2984.  
  2985.     AstCharacterLiteral(LexStream::TokenIndex token_) : character_literal_token(token_)
  2986.     {
  2987.         Ast::kind = Ast::CHARACTER_LITERAL;
  2988.         Ast::class_tag = Ast::EXPRESSION;
  2989.         Ast::generated = 0;
  2990.         AstExpression::value = NULL;
  2991.         AstExpression::symbol = NULL;
  2992.     }
  2993.  
  2994.     virtual ~AstCharacterLiteral();
  2995.  
  2996. #ifdef TEST
  2997.     virtual void Print(LexStream &);
  2998. #endif
  2999.  
  3000.     virtual Ast *Clone(StoragePool *);
  3001.  
  3002.     virtual LexStream::TokenIndex LeftToken()  { return character_literal_token; }
  3003.     virtual LexStream::TokenIndex RightToken() { return character_literal_token; }
  3004. };
  3005.  
  3006. //
  3007. // NullLiteral --> <NULL_EXPRESSION, null_token>
  3008. //
  3009. class AstNullLiteral : public AstExpression
  3010. {
  3011. public:
  3012.     LexStream::TokenIndex null_token;
  3013.  
  3014.     AstNullLiteral(LexStream::TokenIndex token_) : null_token(token_)
  3015.     {
  3016.         Ast::kind = Ast::NULL_LITERAL;
  3017.         Ast::class_tag = Ast::EXPRESSION;
  3018.         Ast::generated = 0;
  3019.         AstExpression::value = NULL;
  3020.         AstExpression::symbol = NULL;
  3021.     }
  3022.  
  3023.     virtual ~AstNullLiteral();
  3024.  
  3025. #ifdef TEST
  3026.     virtual void Print(LexStream &);
  3027. #endif
  3028.  
  3029.     virtual Ast *Clone(StoragePool *);
  3030.  
  3031.     virtual LexStream::TokenIndex LeftToken()  { return null_token; }
  3032.     virtual LexStream::TokenIndex RightToken() { return null_token; }
  3033. };
  3034.  
  3035. //
  3036. // ThisExpression --> <THIS, this_token>
  3037. //
  3038. class AstThisExpression : public AstExpression
  3039. {
  3040. public:
  3041.     LexStream::TokenIndex this_token;
  3042.  
  3043.     AstThisExpression(LexStream::TokenIndex token_) : this_token(token_)
  3044.     {
  3045.         Ast::kind = Ast::THIS_EXPRESSION;
  3046.         Ast::class_tag = Ast::EXPRESSION;
  3047.         Ast::generated = 0;
  3048.         AstExpression::value = NULL;
  3049.         AstExpression::symbol = NULL;
  3050.     }
  3051.  
  3052.     virtual ~AstThisExpression();
  3053.  
  3054. #ifdef TEST
  3055.     virtual void Print(LexStream &);
  3056. #endif
  3057.  
  3058.     virtual Ast *Clone(StoragePool *);
  3059.  
  3060.     virtual LexStream::TokenIndex LeftToken()  { return this_token; }
  3061.     virtual LexStream::TokenIndex RightToken() { return this_token; }
  3062. };
  3063.  
  3064.  
  3065. //
  3066. // SuperExpression --> <SUPER, super_token>
  3067. //
  3068. class AstSuperExpression : public AstExpression
  3069. {
  3070. public:
  3071.     LexStream::TokenIndex super_token;
  3072.  
  3073.     AstSuperExpression(LexStream::TokenIndex token_) : super_token(token_)
  3074.     {
  3075.         Ast::kind = Ast::SUPER_EXPRESSION;
  3076.         Ast::class_tag = Ast::EXPRESSION;
  3077.         Ast::generated = 0;
  3078.         AstExpression::value = NULL;
  3079.         AstExpression::symbol = NULL;
  3080.     }
  3081.  
  3082.     virtual ~AstSuperExpression();
  3083.  
  3084. #ifdef TEST
  3085.     virtual void Print(LexStream &);
  3086. #endif
  3087.  
  3088.     virtual Ast *Clone(StoragePool *);
  3089.  
  3090.     virtual LexStream::TokenIndex LeftToken()  { return super_token; }
  3091.     virtual LexStream::TokenIndex RightToken() { return super_token; }
  3092. };
  3093.  
  3094.  
  3095. //
  3096. // ParenthesizedExpression --> <PARENTHESIZED_EXPRESSION, (_token, Expression, )_token>
  3097. //
  3098. class AstParenthesizedExpression : public AstExpression
  3099. {
  3100. public:
  3101.     LexStream::TokenIndex left_parenthesis_token;
  3102.     AstExpression *expression;
  3103.     LexStream::TokenIndex right_parenthesis_token;
  3104.  
  3105.     AstParenthesizedExpression()
  3106.     {
  3107.         Ast::kind = Ast::PARENTHESIZED_EXPRESSION;
  3108.         Ast::class_tag = Ast::EXPRESSION;
  3109.         Ast::generated = 0;
  3110.         AstExpression::value = NULL;
  3111.         AstExpression::symbol = NULL;
  3112.     }
  3113.  
  3114.     virtual ~AstParenthesizedExpression();
  3115.  
  3116. #ifdef TEST
  3117.     virtual void Print(LexStream &);
  3118. #endif
  3119.  
  3120.     virtual Ast *Clone(StoragePool *);
  3121.  
  3122.     virtual LexStream::TokenIndex LeftToken()  { return left_parenthesis_token; }
  3123.     virtual LexStream::TokenIndex RightToken() { return right_parenthesis_token; }
  3124. };
  3125.  
  3126.  
  3127. //
  3128. // TypeExpression --> <TYPE, Type>
  3129. //
  3130. class AstTypeExpression : public AstExpression
  3131. {
  3132. public:
  3133.     Ast *type;
  3134.  
  3135.     AstTypeExpression(Ast *type_) : type(type_)
  3136.     {
  3137.         Ast::kind = Ast::TYPE;
  3138.         Ast::class_tag = Ast::EXPRESSION;
  3139.         Ast::generated = 0;
  3140.         AstExpression::value = NULL;
  3141.         AstExpression::symbol = NULL;
  3142.     }
  3143.  
  3144.     virtual ~AstTypeExpression();
  3145.  
  3146. #ifdef TEST
  3147.     virtual void Print(LexStream &);
  3148. #endif
  3149.  
  3150.     virtual Ast *Clone(StoragePool *);
  3151.  
  3152.     virtual LexStream::TokenIndex LeftToken()  { return type -> LeftToken(); }
  3153.     virtual LexStream::TokenIndex RightToken() { return type -> RightToken(); }
  3154. };
  3155.  
  3156.  
  3157. //
  3158. // ClassInstanceCreationExpression --> <CLASS_CREATION, new_token, TypeExpression, (_token, Arguments, )_token>
  3159. //
  3160. // Sometimes, during semantic analysis an artificial base_opt expression is constructed.
  3161. // In such a case, the user can determine this condition by testing whether or not
  3162. // dot_token_opt is 0;
  3163. //
  3164. class AstClassInstanceCreationExpression : public AstExpression
  3165. {
  3166. private:
  3167.  
  3168.     StoragePool *pool;
  3169.     AstArray<AstExpression *> *arguments;
  3170.     AstArray<AstExpression *> *local_arguments_opt; // used only for local classes that use enclosed local variables
  3171.  
  3172.     bool add_null_argument;
  3173.  
  3174. public:
  3175.     AstExpression *base_opt;
  3176.     LexStream::TokenIndex dot_token_opt;
  3177.     LexStream::TokenIndex new_token;
  3178.     AstTypeExpression *class_type;
  3179.     LexStream::TokenIndex left_parenthesis_token;
  3180.     LexStream::TokenIndex right_parenthesis_token;
  3181.     AstClassBody *class_body_opt;
  3182.  
  3183.     AstClassInstanceCreationExpression(StoragePool *pool_) : pool(pool_),
  3184.                                                              arguments(NULL),
  3185.                                                              local_arguments_opt(NULL),
  3186.                                                              add_null_argument(false)
  3187.     {
  3188.         Ast::kind = Ast::CLASS_CREATION;
  3189.         Ast::class_tag = Ast::EXPRESSION;
  3190.         Ast::generated = 0;
  3191.         AstExpression::value = NULL;
  3192.         AstExpression::symbol = NULL;
  3193.     }
  3194.  
  3195.     virtual ~AstClassInstanceCreationExpression();
  3196.  
  3197.     inline AstExpression *&Argument(int i) { return (*arguments)[i]; }
  3198.     inline int NumArguments() { return (arguments ? arguments -> Length() : 0); }
  3199.     inline void AllocateArguments(int estimate = 0);
  3200.     inline void AddArgument(AstExpression *);
  3201.  
  3202.     inline AstExpression *&LocalArgument(int i) { return (*local_arguments_opt)[i]; }
  3203.     inline int NumLocalArguments() { return (local_arguments_opt ? local_arguments_opt -> Length() : 0); }
  3204.     inline void AllocateLocalArguments(int estimate = 0);
  3205.     inline void AddLocalArgument(AstExpression *);
  3206.  
  3207.     inline void AddNullArgument() { add_null_argument = true; }
  3208.     inline bool NeedsExtraNullArgument() { return add_null_argument; }
  3209.  
  3210. #ifdef TEST
  3211.     virtual void Print(LexStream &);
  3212. #endif
  3213.  
  3214.     virtual Ast *Clone(StoragePool *);
  3215.  
  3216.     virtual LexStream::TokenIndex LeftToken()
  3217.     {
  3218.         return (base_opt ? base_opt -> LeftToken() : new_token);
  3219.     }
  3220.     virtual LexStream::TokenIndex RightToken() { return (class_body_opt ? class_body_opt -> RightToken() : right_parenthesis_token); }
  3221. };
  3222.  
  3223.  
  3224. //
  3225. // DimExpr --> <DIM, [_token, Expression, ]_token>
  3226. //
  3227. class AstDimExpr : public Ast
  3228. {
  3229. public:
  3230.     LexStream::TokenIndex left_bracket_token;
  3231.     AstExpression *expression;
  3232.     LexStream::TokenIndex right_bracket_token;
  3233.  
  3234.     AstDimExpr()
  3235.     {
  3236.         Ast::kind = Ast::DIM;
  3237.         Ast::class_tag = Ast::NO_TAG;
  3238.         Ast::generated = 0;
  3239.     }
  3240.  
  3241.     virtual ~AstDimExpr();
  3242.  
  3243. #ifdef TEST
  3244.     virtual void Print(LexStream &);
  3245. #endif
  3246.  
  3247.     virtual Ast *Clone(StoragePool *);
  3248.  
  3249.     virtual LexStream::TokenIndex LeftToken()  { return left_bracket_token; }
  3250.     virtual LexStream::TokenIndex RightToken() { return right_bracket_token; }
  3251. };
  3252.  
  3253.  
  3254. //
  3255. // ArrayCreationExpression --> <ARRAY_CREATION, new_token, Type, DimExprs, Brackets>
  3256. //
  3257. class AstArrayCreationExpression : public AstExpression
  3258. {
  3259. private:
  3260.  
  3261.     StoragePool *pool;
  3262.     AstArray<AstBrackets *> *brackets;
  3263.     AstArray<AstDimExpr *> *dim_exprs;
  3264.  
  3265. public:
  3266.     LexStream::TokenIndex new_token;
  3267.     Ast *array_type;
  3268.     AstArrayInitializer *array_initializer_opt;
  3269.  
  3270.     AstArrayCreationExpression(StoragePool *pool_) : pool(pool_),
  3271.                                                      brackets(NULL),
  3272.                                                      dim_exprs(NULL)
  3273.     {
  3274.         Ast::kind = Ast::ARRAY_CREATION;
  3275.         Ast::class_tag = Ast::EXPRESSION;
  3276.         Ast::generated = 0;
  3277.         AstExpression::value = NULL;
  3278.         AstExpression::symbol = NULL;
  3279.     }
  3280.  
  3281.     virtual ~AstArrayCreationExpression();
  3282.  
  3283.     inline AstBrackets *&Brackets(int i) { return (*brackets)[i]; }
  3284.     inline int NumBrackets() { return (brackets ? brackets -> Length() : 0); }
  3285.     inline void AllocateBrackets(int estimate = 0);
  3286.     inline void AddBrackets(AstBrackets *);
  3287.  
  3288.     inline AstDimExpr *&DimExpr(int i) { return (*dim_exprs)[i]; }
  3289.     inline int NumDimExprs() { return (dim_exprs ? dim_exprs -> Length() : 0); }
  3290.     inline void AllocateDimExprs(int estimate = 0);
  3291.     inline void AddDimExpr(AstDimExpr *);
  3292.  
  3293. #ifdef TEST
  3294.     virtual void Print(LexStream &);
  3295. #endif
  3296.  
  3297.     virtual Ast *Clone(StoragePool *);
  3298.  
  3299.     virtual LexStream::TokenIndex LeftToken()  { return new_token; }
  3300.     virtual LexStream::TokenIndex RightToken()
  3301.     {
  3302.         return (array_initializer_opt ? array_initializer_opt -> RightToken()
  3303.                                       : (NumBrackets() > 0 ? Brackets(NumBrackets() - 1) -> RightToken()
  3304.                                                            : DimExpr(NumDimExprs() - 1) -> RightToken()));
  3305.     }
  3306. };
  3307.  
  3308.  
  3309. //
  3310. // FieldAccess --> <DOT, Base, ._token, SimpleName>
  3311. //               | <DOT, TypeExpression, ._token, class_token>
  3312. //               | <DOT, TypeExpression, ._token, this_token>
  3313. //
  3314. // SuperField --> <DOT, TypeExpression, ._token, super_token>
  3315. //
  3316. // Base --> Primary
  3317. //        | Name
  3318. //
  3319. class AstFieldAccess : public AstExpression
  3320. {
  3321. public:
  3322.     enum FieldAccessTag
  3323.     {
  3324.         NONE,
  3325.         CLASS_TAG,
  3326.         THIS_TAG,
  3327.         SUPER_TAG,
  3328.  
  3329.         _num_kinds
  3330.     };
  3331.  
  3332.     AstExpression *base;
  3333.     LexStream::TokenIndex dot_token;
  3334.     LexStream::TokenIndex identifier_token;
  3335.  
  3336.     //
  3337.     // When the right-side of a field access consists of
  3338.     // the keyword this, we resolve it either into a
  3339.     // "this" expression if it refers to "this" type or
  3340.     // to a method call that gives access to the relevant
  3341.     // (private) this$0.
  3342.     //
  3343.     // If the base expression of FieldAccess expression is
  3344.     // of the form expr.this.X, where X is a private variable
  3345.     // that is a member of an outer class, then we resolve it
  3346.     // into a method call to the read_mehod that gives access
  3347.     // to X. In some cases, we also need to resolve field accesses
  3348.     // of the form expr.class.
  3349.     //
  3350.     AstExpression *resolution_opt;
  3351.  
  3352.     AstFieldAccess(FieldAccessTag tag = NONE) : field_access_tag(tag),
  3353.                                                 resolution_opt(NULL)
  3354.     {
  3355.         Ast::kind = Ast::DOT;
  3356.         Ast::class_tag = Ast::EXPRESSION;
  3357.         Ast::generated = 0;
  3358.         AstExpression::value = NULL;
  3359.         AstExpression::symbol = NULL;
  3360.     }
  3361.  
  3362.     virtual ~AstFieldAccess();
  3363.  
  3364.     bool IsNameAccess()  { return field_access_tag == NONE; }
  3365.     bool IsThisAccess()  { return field_access_tag == THIS_TAG; }
  3366.     bool IsSuperAccess() { return field_access_tag == SUPER_TAG; }
  3367.     bool IsClassAccess() { return field_access_tag == CLASS_TAG; }
  3368.  
  3369. #ifdef TEST
  3370.     virtual void Print(LexStream &);
  3371. #endif
  3372.  
  3373.     virtual Ast *Clone(StoragePool *);
  3374.  
  3375.     virtual LexStream::TokenIndex LeftToken()  { return base -> LeftToken(); }
  3376.     virtual LexStream::TokenIndex RightToken() { return identifier_token; }
  3377.  
  3378. private:
  3379.     FieldAccessTag field_access_tag;
  3380. };
  3381.  
  3382.  
  3383. //
  3384. // MethodInvocation --> <CALL, Method, (_token, Arguments, )_token>
  3385. //
  3386. // Method --> SimpleName
  3387. //          | FieldAccess
  3388. //
  3389. class AstMethodInvocation : public AstExpression
  3390. {
  3391. private:
  3392.  
  3393.     StoragePool *pool;
  3394.     AstArray<AstExpression *> *arguments;
  3395.  
  3396. public:
  3397.     AstExpression *method;
  3398.     LexStream::TokenIndex left_parenthesis_token;
  3399.     LexStream::TokenIndex right_parenthesis_token;
  3400.  
  3401.     //
  3402.     // When a method refers to a member in an enclosing scope,
  3403.     // it is mapped into a new expression that creates a path to
  3404.     // the member in question.
  3405.     //
  3406.     AstExpression *resolution_opt;
  3407.  
  3408.     AstMethodInvocation(StoragePool *pool_) : pool(pool_),
  3409.                                               arguments(NULL),
  3410.                                               resolution_opt(NULL)
  3411.     {
  3412.         Ast::kind = Ast::CALL;
  3413.         Ast::class_tag = Ast::EXPRESSION;
  3414.         Ast::generated = 0;
  3415.         AstExpression::value = NULL;
  3416.         AstExpression::symbol = NULL;
  3417.     }
  3418.  
  3419.     virtual ~AstMethodInvocation();
  3420.  
  3421.     inline AstExpression *&Argument(int i) { return (*arguments)[i]; }
  3422.     inline int NumArguments() { return (arguments ? arguments -> Length() : 0); }
  3423.     inline void AllocateArguments(int estimate = 0);
  3424.     inline void AddArgument(AstExpression *);
  3425.  
  3426. #ifdef TEST
  3427.     virtual void Print(LexStream &);
  3428. #endif
  3429.  
  3430.     virtual Ast *Clone(StoragePool *);
  3431.  
  3432.     virtual LexStream::TokenIndex LeftToken() { return method -> LeftToken(); }
  3433.     virtual LexStream::TokenIndex RightToken() { return right_parenthesis_token; }
  3434. };
  3435.  
  3436.  
  3437. //
  3438. // ArrayAccess --> <ARRAY_ACCESS, Base, [_token, Expression, ]_token>
  3439. //
  3440. class AstArrayAccess : public AstExpression
  3441. {
  3442. public:
  3443.     AstExpression *base;
  3444.     LexStream::TokenIndex left_bracket_token;
  3445.     AstExpression *expression;
  3446.     LexStream::TokenIndex right_bracket_token;
  3447.  
  3448.     AstArrayAccess()
  3449.     {
  3450.         Ast::kind = Ast::ARRAY_ACCESS;
  3451.         Ast::class_tag = Ast::EXPRESSION;
  3452.         Ast::generated = 0;
  3453.         AstExpression::value = NULL;
  3454.         AstExpression::symbol = NULL;
  3455.     }
  3456.  
  3457.     virtual ~AstArrayAccess();
  3458.  
  3459. #ifdef TEST
  3460.     virtual void Print(LexStream &);
  3461. #endif
  3462.  
  3463.     virtual Ast *Clone(StoragePool *);
  3464.  
  3465.     virtual LexStream::TokenIndex LeftToken() { return base -> LeftToken(); }
  3466.     virtual LexStream::TokenIndex RightToken() { return right_bracket_token; }
  3467. };
  3468.  
  3469.  
  3470. //
  3471. // UnaryExpression --> PreUnaryExpression
  3472. //                   | PostUnaryExpression
  3473. //                   | CastExpression
  3474. //
  3475. // PostUnaryExpression --> <POST_UNARY, PostUnaryTag, Expression, PostOperator>
  3476. //
  3477. // PostUnaryTag --> PLUSPLUS | MINUSMINUS
  3478. //
  3479. // PostOperator --> ++_token | --_token
  3480. //
  3481. class AstPostUnaryExpression : public AstExpression
  3482. {
  3483. public:
  3484.     enum PostUnaryExpressionTag
  3485.     {
  3486.         NONE,
  3487.         PLUSPLUS,
  3488.         MINUSMINUS,
  3489.  
  3490.         _num_kinds
  3491.     };
  3492.  
  3493.     PostUnaryExpressionTag post_unary_tag;
  3494.     AstExpression *expression;
  3495.     LexStream::TokenIndex post_operator_token;
  3496.  
  3497.     //
  3498.     // When the left-hand side of an assignment is a name that refers
  3499.     // to a private field in an enclosing scope, the access method
  3500.     // that gives write-permission to that field is recorded here.
  3501.     //
  3502.     MethodSymbol *write_method;
  3503.  
  3504.     AstPostUnaryExpression(PostUnaryExpressionTag tag_) : post_unary_tag(tag_),
  3505.                                                           write_method(NULL)
  3506.     {
  3507.         Ast::kind = Ast::POST_UNARY;
  3508.         Ast::class_tag = Ast::EXPRESSION;
  3509.         Ast::generated = 0;
  3510.         AstExpression::value = NULL;
  3511.         AstExpression::symbol = NULL;
  3512.     }
  3513.  
  3514.     virtual ~AstPostUnaryExpression();
  3515.  
  3516. #ifdef TEST
  3517.     virtual void Print(LexStream &);
  3518. #endif
  3519.  
  3520.     virtual Ast *Clone(StoragePool *);
  3521.  
  3522.     virtual LexStream::TokenIndex LeftToken()  { return expression -> LeftToken(); }
  3523.     virtual LexStream::TokenIndex RightToken() { return post_operator_token; }
  3524. };
  3525.  
  3526.  
  3527. //
  3528. // PreUnaryExpression -->  <PRE_UNARY, PreUnaryTag, PreOperator, Expression>
  3529. //
  3530. // PreUnaryTag --> PLUS | MINUS | TWIDDLE | NOT | PLUSPLUS | MINUSMINUS
  3531. //
  3532. // PreOperator --> +_token | -_token | ~_token | !_token | ++_token | --_token
  3533. //
  3534. class AstPreUnaryExpression : public AstExpression
  3535. {
  3536. public:
  3537.     enum PreUnaryExpressionTag
  3538.     {
  3539.         NONE,
  3540.         PLUSPLUS,
  3541.         MINUSMINUS,
  3542.         PLUS,
  3543.         MINUS,
  3544.         TWIDDLE,
  3545.         NOT,
  3546.  
  3547.         _num_kinds
  3548.     };
  3549.  
  3550.     PreUnaryExpressionTag pre_unary_tag;
  3551.     LexStream::TokenIndex pre_operator_token;
  3552.     AstExpression *expression;
  3553.  
  3554.     //
  3555.     // When the left-hand side of an assignment is a name that refers
  3556.     // to a private field in an enclosing scope, the access method
  3557.     // that gives write-permission to that field is recorded here.
  3558.     //
  3559.     MethodSymbol *write_method;
  3560.  
  3561.     AstPreUnaryExpression(PreUnaryExpressionTag tag_) : pre_unary_tag(tag_),
  3562.                                                         write_method(NULL)
  3563.     {
  3564.         Ast::kind = Ast::PRE_UNARY;
  3565.         Ast::class_tag = Ast::EXPRESSION;
  3566.         Ast::generated = 0;
  3567.         AstExpression::value = NULL;
  3568.         AstExpression::symbol = NULL;
  3569.     }
  3570.  
  3571.     virtual ~AstPreUnaryExpression();
  3572.  
  3573. #ifdef TEST
  3574.     virtual void Print(LexStream &);
  3575. #endif
  3576.  
  3577.     virtual Ast *Clone(StoragePool *);
  3578.  
  3579.     virtual LexStream::TokenIndex LeftToken()  { return pre_operator_token; }
  3580.     virtual LexStream::TokenIndex RightToken() { return expression -> RightToken(); }
  3581. };
  3582.  
  3583.  
  3584. //
  3585. // CastExpression --> <cAstkind, (_token_opt, Type_opt, Brackets )_token_opt, Expression>
  3586. //
  3587. // cAstkind --> CAST
  3588. //             | CHECK_AND_CAST
  3589. //
  3590. // NOTE that the optional symbols above are absent only when the compiler inserts
  3591. // a CAST conversion node into the program.
  3592. //
  3593. class AstCastExpression : public AstExpression
  3594. {
  3595. private:
  3596.  
  3597.     StoragePool *pool;
  3598.     AstArray<AstBrackets *> *brackets;
  3599.  
  3600. public:
  3601.     LexStream::TokenIndex left_parenthesis_token_opt;
  3602.     Ast *type_opt;
  3603.     LexStream::TokenIndex right_parenthesis_token_opt;
  3604.     AstExpression *expression;
  3605.  
  3606.     AstCastExpression(StoragePool *pool_) : pool(pool_),
  3607.                                             brackets(NULL)
  3608.     {
  3609.         Ast::kind = Ast::CAST;
  3610.         Ast::class_tag = Ast::EXPRESSION;
  3611.         Ast::generated = 0;
  3612.         AstExpression::value = NULL;
  3613.         AstExpression::symbol = NULL;
  3614.     }
  3615.  
  3616.     virtual ~AstCastExpression();
  3617.  
  3618.     inline AstBrackets *&Brackets(int i) { return (*brackets)[i]; }
  3619.     inline int NumBrackets() { return (brackets ? brackets -> Length() : 0); }
  3620.     inline void AllocateBrackets(int estimate = 0);
  3621.     inline void AddBrackets(AstBrackets *);
  3622.  
  3623. #ifdef TEST
  3624.     virtual void Print(LexStream &);
  3625. #endif
  3626.  
  3627.     virtual Ast *Clone(StoragePool *);
  3628.  
  3629.     virtual LexStream::TokenIndex LeftToken()
  3630.     {
  3631.         return (left_parenthesis_token_opt ? left_parenthesis_token_opt : expression -> LeftToken());
  3632.     }
  3633.     virtual LexStream::TokenIndex RightToken() { return expression -> RightToken(); }
  3634. };
  3635.  
  3636.  
  3637. //
  3638. // BinaryExpression --> <BINARY, BinaryTag, LeftExpression, BinaryOperator, RightExpression>
  3639. //
  3640. // LeftExpression --> Expression
  3641. //
  3642. // RightExpression --> Expression
  3643. //                   | type
  3644. //
  3645. // BinaryTag --> STAR | SLASH | MOD | PLUS | MINUS | LEFT_SHIFT | RIGHT_SHIFT | UNSIGNED_RIGHT_SHIFT |
  3646. //               INSTANCEOF | LESS | GREATER | LESS_EQUAL | GREATER_EQUAL | EQUAL_EQUAL | NOT_EQUAL |
  3647. //               AND | XOR | IOR | AND_AND | OR_OR
  3648. //
  3649. // BinaryOperator --> *_token | /_token | %_token | +_token | -_token | <<_token | >>_token | >>>_token |
  3650. //                    instanceof_token | <_token | >_token | <=_token | >=_token | ==_token | !=_token |
  3651. //                    &_token | ^_token | |_token | &&_token | ||_token
  3652. //
  3653. class AstBinaryExpression : public AstExpression
  3654. {
  3655. public:
  3656.     enum BinaryExpressionTag
  3657.     {
  3658.         NONE,
  3659.         STAR,
  3660.         SLASH,
  3661.         MOD,
  3662.         PLUS,
  3663.         MINUS,
  3664.         LEFT_SHIFT,
  3665.         RIGHT_SHIFT,
  3666.         UNSIGNED_RIGHT_SHIFT,
  3667.         INSTANCEOF,
  3668.         LESS,
  3669.         GREATER,
  3670.         AND,
  3671.         XOR,
  3672.         IOR,
  3673.         AND_AND,
  3674.         OR_OR,
  3675.  
  3676.         LESS_EQUAL,
  3677.         GREATER_EQUAL,
  3678.         EQUAL_EQUAL,
  3679.         NOT_EQUAL,
  3680.  
  3681.         _num_kinds
  3682.     };
  3683.  
  3684.     BinaryExpressionTag binary_tag;
  3685.     AstExpression *left_expression;
  3686.     LexStream::TokenIndex binary_operator_token;
  3687.     AstExpression *right_expression;
  3688.  
  3689.     AstBinaryExpression(BinaryExpressionTag tag_) : binary_tag(tag_)
  3690.     {
  3691.         Ast::kind = Ast::BINARY;
  3692.         Ast::class_tag = Ast::EXPRESSION;
  3693.         Ast::generated = 0;
  3694.         AstExpression::value = NULL;
  3695.         AstExpression::symbol = NULL;
  3696.     }
  3697.  
  3698.     virtual ~AstBinaryExpression();
  3699.  
  3700. #ifdef TEST
  3701.     virtual void Print(LexStream &);
  3702. #endif
  3703.  
  3704.     virtual Ast *Clone(StoragePool *);
  3705.  
  3706.     virtual LexStream::TokenIndex LeftToken()  { return left_expression -> LeftToken(); }
  3707.     virtual LexStream::TokenIndex RightToken() { return right_expression -> RightToken(); }
  3708. };
  3709.  
  3710.  
  3711. //
  3712. // ConditionalExpression --> <CONDITIONAL, Expression, ?_token, Expression, :_token, Expression>
  3713. //
  3714. class AstConditionalExpression : public AstExpression
  3715. {
  3716. public:
  3717.     AstExpression *test_expression;
  3718.     LexStream::TokenIndex question_token;
  3719.     AstExpression *true_expression;
  3720.     LexStream::TokenIndex colon_token;
  3721.     AstExpression *false_expression;
  3722.  
  3723.     AstConditionalExpression()
  3724.     {
  3725.         Ast::kind = Ast::CONDITIONAL;
  3726.         Ast::class_tag = Ast::EXPRESSION;
  3727.         Ast::generated = 0;
  3728.         AstExpression::value = NULL;
  3729.         AstExpression::symbol = NULL;
  3730.     }
  3731.  
  3732.     virtual ~AstConditionalExpression();
  3733.  
  3734. #ifdef TEST
  3735.     virtual void Print(LexStream &);
  3736. #endif
  3737.  
  3738.     virtual Ast *Clone(StoragePool *);
  3739.  
  3740.     virtual LexStream::TokenIndex LeftToken()  { return test_expression -> LeftToken(); }
  3741.     virtual LexStream::TokenIndex RightToken() { return false_expression -> RightToken(); }
  3742. };
  3743.  
  3744.  
  3745. //
  3746. // Assignment --> <ASSIGNMENT, AssignmentTag, LeftHandSide, AssignmentOperator, Expression>
  3747. //
  3748. // AssignmentTag --> EQUAL | STAR_EQUAL | SLASH_EQUAL | MOD_EQUAL | PLUS_EQUAL | MINUS_EQUAL |
  3749. //                   LEFT_SHIFT_EQUAL | RIGHT_SHIFT_EQUAL | UNSIGNED_RIGHT_SHIFT_EQUAL |
  3750. //                   AND_EQUAL | XOR_EQUAL | IOR_EQUAL
  3751. //
  3752. // LeftHandSide --> Name | FieldAccess | ArrayAccess
  3753. //                | <cAstkind, (_token_opt, Type_opt, Brackets )_token_opt, Name>
  3754. //                | <cAstkind, (_token_opt, Type_opt, Brackets )_token_opt, FieldAccess>
  3755. //                | <cAstkind, (_token_opt, Type_opt, Brackets )_token_opt, ArrayAccess>
  3756. //
  3757. // NOTE: that a LeftHandSide appears as a cast node only when the assignment_operator in question
  3758. // is of the form "op=" and the application of the operator requires a casting of the value of the
  3759. // left-hand side.
  3760. //
  3761. // AssignmentOperator --> =_token | *=_token | /=_token | %=_token | +=_token | -=_token |
  3762. //                        <<=_token | >>=_token | >>>=_token | &=_token | ^=_token | |=_token
  3763. //
  3764. class AstAssignmentExpression : public AstExpression
  3765. {
  3766. public:
  3767.     enum AssignmentExpressionTag
  3768.     {
  3769.         NONE,
  3770.         EQUAL,
  3771.         STAR_EQUAL,
  3772.         SLASH_EQUAL,
  3773.         MOD_EQUAL,
  3774.         PLUS_EQUAL,
  3775.         MINUS_EQUAL,
  3776.         LEFT_SHIFT_EQUAL,
  3777.         RIGHT_SHIFT_EQUAL,
  3778.         UNSIGNED_RIGHT_SHIFT_EQUAL,
  3779.  
  3780.  
  3781.         AND_EQUAL,
  3782.         XOR_EQUAL,
  3783.         IOR_EQUAL,
  3784.  
  3785.         _num_kinds
  3786.     };
  3787.  
  3788.     //
  3789.     // When the left-hand side of an assignment is a name that refers
  3790.     // to a private field in an enclosing scope, the access method
  3791.     // that gives write-permission to that field is recorded here.
  3792.     //
  3793.     MethodSymbol *write_method;
  3794.  
  3795.     AssignmentExpressionTag assignment_tag;
  3796.     AstExpression *left_hand_side;
  3797.     LexStream::TokenIndex assignment_operator_token;
  3798.     AstExpression *expression;
  3799.  
  3800.     AstAssignmentExpression(AssignmentExpressionTag tag_, LexStream::TokenIndex token_) : assignment_tag(tag_),
  3801.                                                                                           assignment_operator_token(token_),
  3802.                                                                                           write_method(NULL)
  3803.     {
  3804.         Ast::kind = Ast::ASSIGNMENT;
  3805.         Ast::class_tag = Ast::EXPRESSION;
  3806.         Ast::generated = 0;
  3807.         AstExpression::value = NULL;
  3808.         AstExpression::symbol = NULL;
  3809.     }
  3810.  
  3811.     virtual ~AstAssignmentExpression();
  3812.  
  3813. #ifdef TEST
  3814.     virtual void Print(LexStream &);
  3815. #endif
  3816.  
  3817.     virtual Ast *Clone(StoragePool *);
  3818.  
  3819.     virtual LexStream::TokenIndex LeftToken()  { return left_hand_side -> LeftToken(); }
  3820.     virtual LexStream::TokenIndex RightToken() { return expression -> RightToken(); }
  3821. };
  3822.  
  3823.  
  3824. //
  3825. // Given an Ast tree, check whether or not it is a Name - simple or qualified.
  3826. //
  3827. inline bool Ast::IsName()
  3828. {
  3829.     Ast *name = this;
  3830.     for (AstFieldAccess *field_access = name -> FieldAccessCast(); field_access && field_access -> IsNameAccess();
  3831.                                                                    field_access = name -> FieldAccessCast())
  3832.         name = field_access -> base;
  3833.     return (name -> SimpleNameCast() != NULL);
  3834. }
  3835.  
  3836.  
  3837. //
  3838. // Given an Ast tree, check whether or not it is a simple name or
  3839. // a field access consisting only of simple names or keywords.
  3840. //
  3841. inline bool Ast::IsSimpleNameOrFieldAccess()
  3842. {
  3843.     Ast *name = this;
  3844.     for (AstFieldAccess *field_access = name -> FieldAccessCast(); field_access; field_access = name -> FieldAccessCast())
  3845.         name = field_access -> base;
  3846.     return (name -> SimpleNameCast() || name -> TypeExpressionCast());
  3847. }
  3848.  
  3849.  
  3850. //
  3851. // Do we have a simple 'super' expression or a field of the form XXX.super
  3852. //
  3853. inline bool Ast::IsSuperExpression()
  3854. {
  3855.     return (this -> SuperExpressionCast() || (this -> FieldAccessCast() && this -> FieldAccessCast() -> IsSuperAccess()));
  3856.  
  3857. }
  3858.  
  3859. //
  3860. // Given an Ast tree, check whether or not it is a Name - simple or qualified.
  3861. //
  3862. inline bool Ast::IsLeftHandSide()
  3863. {
  3864.     return (this -> SimpleNameCast() || this -> FieldAccessCast() || this -> ArrayAccessCast());
  3865. }
  3866.  
  3867.  
  3868. //
  3869. // Given an Ast tree, check whether or not it is a Name - simple or qualified.
  3870. //
  3871. inline bool Ast::IsGenerated()
  3872. {
  3873.     return (generated == 1);
  3874. }
  3875.  
  3876.  
  3877. //
  3878. // This Storage pool is modeled after the Dynamic arrays. The difference is that
  3879. // instead of a Next() function we have an alloc(size_t) function. The value
  3880. // of the size_t argument represents the size of the object to allocate.
  3881. //
  3882. class StoragePool
  3883. {
  3884. public:
  3885.  
  3886.     typedef void *Cell;
  3887.  
  3888.     inline size_t Blksize() { return (1 << log_blksize); }
  3889.  
  3890. private:
  3891.  
  3892.     Cell **base;
  3893.     int base_size,
  3894.         top,
  3895.         size;
  3896.  
  3897.     size_t log_blksize,
  3898.            base_increment;
  3899.  
  3900.     //
  3901.     // Allocate another block of storage for the storage pool
  3902.     //
  3903.     void AllocateMoreSpace()
  3904.     {
  3905.         //
  3906.         // The variable size always indicates the maximum number of
  3907.         // cells that has been allocated for the storage pool.
  3908.         // Initially, it is set to 0 to indicate that the pool is empty.
  3909.         // The pool of available elements is divided into segments of size
  3910.         // 2**log_blksize each. Each segment is pointed to by a slot in
  3911.         // the array base.
  3912.         //
  3913.         // By dividing size by the size of the segment we obtain the
  3914.         // index for the next segment in base. If base is full, it is
  3915.         // reallocated.
  3916.         //
  3917.         //
  3918.         int k = size >> log_blksize; /* which segment? */
  3919.  
  3920.         //
  3921.         // If the base is overflowed, reallocate it and initialize the new elements to NULL.
  3922.         //
  3923.         if (k == base_size)
  3924.         {
  3925.             int old_base_size = base_size;
  3926.             Cell **old_base = base;
  3927.  
  3928.             base_size += base_increment;
  3929.             base = ::new Cell*[base_size];
  3930.  
  3931.             if (old_base != NULL)
  3932.             {
  3933.                 memmove(base, old_base, old_base_size * sizeof(Cell *));
  3934.                 delete [] old_base;
  3935.             }
  3936.             memset(&base[old_base_size], 0, (base_size - old_base_size) * sizeof(Cell *));
  3937.         }
  3938.  
  3939.         //
  3940.         // If the slot "k" does not already contain a segment,
  3941.         // we allocate a new segment and place its adjusted address in
  3942.         // base[k]. The adjustment allows us to index the segment directly,
  3943.         // instead of having to perform a subtraction for each reference.
  3944.         // See operator[] below.
  3945.         //
  3946.         if (base[k] == NULL)
  3947.         {
  3948.             base[k] = ::new Cell[Blksize()];
  3949.             base[k] -= size;
  3950.         }
  3951.  
  3952.         //
  3953.         // Finally, we update SIZE.
  3954.         //
  3955.         size += Blksize();
  3956.  
  3957.         return;
  3958.     }
  3959.  
  3960. public:
  3961.  
  3962.     //
  3963.     // Constructor of a storage pool
  3964.     //
  3965.     StoragePool(size_t num_tokens)
  3966.     {
  3967.         //
  3968.         // Make a guess on the size that will be required for the ast
  3969.         // based on the number of tokens. The ratio for the bodies is
  3970.         // usually 40 to 1. We will double the base to add to account
  3971.         // for the headers
  3972.         //
  3973.         size_t estimate = num_tokens * 10; // recall that each cell is a-byte word. So, 10 * 4 = 40
  3974.  
  3975.         //
  3976.         // Find a block of size 2**log_blksize that is large enough
  3977.         // to satisfy our estimate.
  3978.         //
  3979.         for (log_blksize = 8; (((unsigned) 1 << log_blksize) < estimate) && (log_blksize < 31); log_blksize++)
  3980.             ;
  3981.  
  3982.         //
  3983.         // If the size of the block found is < 1k, allocate a block of size 1k
  3984.         // with one slot to spare, just in case.
  3985.         // If the size is less than 16k, then break it up into equal blocks
  3986.         // of size 1k;
  3987.         // Otherwise, fragment it into pieces of size 16k.
  3988.         //
  3989.         if (log_blksize < 8)
  3990.         {
  3991.             base_increment = 1;
  3992.             log_blksize = 8;
  3993.         }
  3994.         else if (log_blksize < 13)
  3995.         {
  3996.             base_increment = (unsigned) 1 << (log_blksize - 8);
  3997.             log_blksize = 8;
  3998.         }
  3999.         else if (log_blksize < 17)
  4000.         {
  4001.             base_increment = (unsigned) 1 << (log_blksize - 10);
  4002.             log_blksize = 10;
  4003.         }
  4004.         else
  4005.         {
  4006.             base_increment = (unsigned) 1 << (log_blksize - 12); // assume we won't be allocating more than this many blocks.
  4007.             log_blksize = 12;
  4008.         }
  4009.  
  4010.         //
  4011.         // Double the size of the base in order to allocate extra space for the headers
  4012.         // and add a little margin for stuff like extra Cast node and computation of
  4013.         // static expressions that require cloning.
  4014.         //
  4015.         base_increment = (base_increment << 1) + 3;
  4016.  
  4017.         base_size = 0;
  4018.         size = 0;
  4019.         top = 0;
  4020.         base = NULL;
  4021.     }
  4022.  
  4023.     //
  4024.     // Destructor of a storage pool
  4025.     //
  4026.     ~StoragePool()
  4027.     {
  4028.         for (int k = (size >> log_blksize) - 1; k >= 0; k--)
  4029.         {
  4030.             size -= Blksize();
  4031.             base[k] += size;
  4032.             delete [] base[k];
  4033.         }
  4034.  
  4035.         delete [] base;
  4036.     }
  4037.  
  4038.     //
  4039.     // alloc allocates an object of size n in the pool and
  4040.     // returns a pointer to it.
  4041.     //
  4042.     inline void *Alloc(size_t n)
  4043.     {
  4044.         size_t i = top,
  4045.                chunk_size = ((n + sizeof(Cell) - 1) / sizeof(Cell));
  4046.         top += chunk_size;
  4047.         if (top > size)
  4048.         {
  4049.             assert(chunk_size <= Blksize() && "we cannot allocate a chunk of storage that is larger than the block !");
  4050.  
  4051.             i = size;
  4052.             top = size + chunk_size;
  4053.             AllocateMoreSpace();
  4054.         }
  4055.  
  4056.         return ((void *) &(base[i >> log_blksize] [i]));
  4057.     }
  4058.  
  4059.     //
  4060.     // Return length of the amount of storage that has been allocated so far.
  4061.     //
  4062.     inline size_t Length() { return top; }
  4063.  
  4064.     //
  4065.     // This function is used to reset the Storage pool. This action automatically
  4066.     // invalidates all objects that had been allocated in the pool. At least,
  4067.     // YOU should assume it does!!!
  4068.     //
  4069.     inline void Reset(const int n = 0)
  4070.     {
  4071.         if (n < 0 || n > size)
  4072.             assert(false);
  4073.         top = n;
  4074.     }
  4075.  
  4076.     //
  4077.     // This function frees up all dynamic space that
  4078.     // was allocated for this storage pool.
  4079.     //
  4080.     inline void Destroy()
  4081.     {
  4082.         for (int k = (size >> log_blksize) - 1; k >= 0; k--)
  4083.         {
  4084.             size -= Blksize();
  4085.             base[k] += size;
  4086.             delete [] base[k];
  4087.             base[k] = NULL;
  4088.         }
  4089.  
  4090.         delete [] base;
  4091.         base = NULL;
  4092.         base_size = 0;
  4093.  
  4094.         Reset();
  4095.  
  4096.         return;
  4097.     }
  4098.  
  4099.     // ********************************************************************************************** //
  4100.  
  4101.     inline AstArray<LexStream::TokenIndex> *NewTokenIndexArray(unsigned size = 0)
  4102.     {
  4103.         return new (Alloc(sizeof(AstArray<LexStream::TokenIndex>))) AstArray<LexStream::TokenIndex>((StoragePool *) this, size);
  4104.     }
  4105.  
  4106.     inline AstArray<Ast *> *NewAstArray(unsigned size = 0)
  4107.     {
  4108.         return new (Alloc(sizeof(AstArray<Ast *>))) AstArray<Ast *>((StoragePool *) this, size);
  4109.     }
  4110.  
  4111.     inline AstArray<CaseElement *> *NewCaseElementArray(unsigned size = 0)
  4112.     {
  4113.         return new (Alloc(sizeof(AstArray<CaseElement *>))) AstArray<CaseElement *>((StoragePool *) this, size);
  4114.     }
  4115.  
  4116.     inline AstListNode *NewListNode()
  4117.     {
  4118.         return new (Alloc(sizeof(AstListNode))) AstListNode();
  4119.     }
  4120.  
  4121.     inline AstBlock *NewBlock()
  4122.     {
  4123.         return new (Alloc(sizeof(AstBlock))) AstBlock((StoragePool *) this);
  4124.     }
  4125.  
  4126.     inline AstPrimitiveType *NewPrimitiveType(Ast::Kind kind, LexStream::TokenIndex token)
  4127.     {
  4128.         return new (Alloc(sizeof(AstPrimitiveType))) AstPrimitiveType(kind, token);
  4129.     }
  4130.  
  4131.     inline AstArrayType *NewArrayType()
  4132.     {
  4133.         return new (Alloc(sizeof(AstArrayType))) AstArrayType((StoragePool *) this);
  4134.     }
  4135.  
  4136.     inline AstSimpleName *NewSimpleName(LexStream::TokenIndex token)
  4137.     {
  4138.         return new (Alloc(sizeof(AstSimpleName))) AstSimpleName(token);
  4139.     }
  4140.  
  4141.     inline AstPackageDeclaration *NewPackageDeclaration()
  4142.     {
  4143.         return new (Alloc(sizeof(AstPackageDeclaration))) AstPackageDeclaration();
  4144.     }
  4145.  
  4146.     inline AstImportDeclaration *NewImportDeclaration()
  4147.     {
  4148.         return new (Alloc(sizeof(AstImportDeclaration))) AstImportDeclaration();
  4149.     }
  4150.  
  4151.     inline AstCompilationUnit *NewCompilationUnit()
  4152.     {
  4153.         return new (Alloc(sizeof(AstCompilationUnit))) AstCompilationUnit((StoragePool *) this);
  4154.     }
  4155.  
  4156.     inline AstModifier *NewModifier(Ast::Kind kind, LexStream::TokenIndex token)
  4157.     {
  4158.         return new (Alloc(sizeof(AstModifier))) AstModifier(kind, token);
  4159.     }
  4160.  
  4161.     inline AstEmptyDeclaration *NewEmptyDeclaration(LexStream::TokenIndex token)
  4162.     {
  4163.         return new (Alloc(sizeof(AstEmptyDeclaration))) AstEmptyDeclaration(token);
  4164.     }
  4165.  
  4166.     inline AstClassBody *NewClassBody()
  4167.     {
  4168.         return new (Alloc(sizeof(AstClassBody))) AstClassBody((StoragePool *) this);
  4169.     }
  4170.  
  4171.     inline AstClassDeclaration *NewClassDeclaration()
  4172.     {
  4173.         return new (Alloc(sizeof(AstClassDeclaration))) AstClassDeclaration((StoragePool *) this);
  4174.     }
  4175.  
  4176.     inline AstArrayInitializer *NewArrayInitializer()
  4177.     {
  4178.         return new (Alloc(sizeof(AstArrayInitializer))) AstArrayInitializer((StoragePool *) this);
  4179.     }
  4180.  
  4181.     inline AstBrackets *NewBrackets(LexStream::TokenIndex left, LexStream::TokenIndex right)
  4182.     {
  4183.         return new (Alloc(sizeof(AstBrackets))) AstBrackets(left, right);
  4184.     }
  4185.  
  4186.     inline AstVariableDeclaratorId *NewVariableDeclaratorId()
  4187.     {
  4188.         return new (Alloc(sizeof(AstVariableDeclaratorId))) AstVariableDeclaratorId((StoragePool *) this);
  4189.     }
  4190.  
  4191.     inline AstVariableDeclarator *NewVariableDeclarator()
  4192.     {
  4193.         return new (Alloc(sizeof(AstVariableDeclarator))) AstVariableDeclarator();
  4194.     }
  4195.  
  4196.     inline AstFieldDeclaration *NewFieldDeclaration()
  4197.     {
  4198.         return new (Alloc(sizeof(AstFieldDeclaration))) AstFieldDeclaration((StoragePool *) this);
  4199.     }
  4200.  
  4201.     inline AstFormalParameter *NewFormalParameter()
  4202.     {
  4203.         return new (Alloc(sizeof(AstFormalParameter))) AstFormalParameter((StoragePool *) this);
  4204.     }
  4205.  
  4206.     inline AstMethodDeclarator *NewMethodDeclarator()
  4207.     {
  4208.         return new (Alloc(sizeof(AstMethodDeclarator))) AstMethodDeclarator((StoragePool *) this);
  4209.     }
  4210.  
  4211.     inline AstMethodDeclaration *NewMethodDeclaration()
  4212.     {
  4213.         return new (Alloc(sizeof(AstMethodDeclaration))) AstMethodDeclaration((StoragePool *) this);
  4214.     }
  4215.  
  4216.     inline AstStaticInitializer *NewStaticInitializer()
  4217.     {
  4218.         return new (Alloc(sizeof(AstStaticInitializer))) AstStaticInitializer();
  4219.     }
  4220.  
  4221.     inline AstThisCall *NewThisCall()
  4222.     {
  4223.         return new (Alloc(sizeof(AstThisCall))) AstThisCall((StoragePool *) this);
  4224.     }
  4225.  
  4226.     inline AstSuperCall *NewSuperCall()
  4227.     {
  4228.         return new (Alloc(sizeof(AstSuperCall))) AstSuperCall((StoragePool *) this);
  4229.     }
  4230.  
  4231.     inline AstConstructorBlock *NewConstructorBlock()
  4232.     {
  4233.         return new (Alloc(sizeof(AstConstructorBlock))) AstConstructorBlock((StoragePool *) this);
  4234.     }
  4235.  
  4236.     inline AstConstructorDeclaration *NewConstructorDeclaration()
  4237.     {
  4238.         return new (Alloc(sizeof(AstConstructorDeclaration))) AstConstructorDeclaration((StoragePool *) this);
  4239.     }
  4240.  
  4241.     inline AstInterfaceDeclaration *NewInterfaceDeclaration()
  4242.     {
  4243.         return new (Alloc(sizeof(AstInterfaceDeclaration))) AstInterfaceDeclaration((StoragePool *) this);
  4244.     }
  4245.  
  4246.     inline AstLocalVariableDeclarationStatement *NewLocalVariableDeclarationStatement()
  4247.     {
  4248.         return new (Alloc(sizeof(AstLocalVariableDeclarationStatement))) AstLocalVariableDeclarationStatement((StoragePool *) this);
  4249.     }
  4250.  
  4251.     inline AstIfStatement *NewIfStatement()
  4252.     {
  4253.         return new (Alloc(sizeof(AstIfStatement))) AstIfStatement();
  4254.     }
  4255.  
  4256.     inline AstEmptyStatement *NewEmptyStatement(LexStream::TokenIndex token)
  4257.     {
  4258.         return new (Alloc(sizeof(AstEmptyStatement))) AstEmptyStatement(token);
  4259.     }
  4260.  
  4261.     inline AstExpressionStatement *NewExpressionStatement()
  4262.     {
  4263.         return new (Alloc(sizeof(AstExpressionStatement))) AstExpressionStatement();
  4264.     }
  4265.  
  4266.     inline AstCaseLabel *NewCaseLabel()
  4267.     {
  4268.         return new (Alloc(sizeof(AstCaseLabel))) AstCaseLabel();
  4269.     }
  4270.  
  4271.     inline AstDefaultLabel *NewDefaultLabel()
  4272.     {
  4273.         return new (Alloc(sizeof(AstDefaultLabel))) AstDefaultLabel();
  4274.     }
  4275.  
  4276.     inline AstSwitchBlockStatement *NewSwitchBlockStatement()
  4277.     {
  4278.         return new (Alloc(sizeof(AstSwitchBlockStatement))) AstSwitchBlockStatement((StoragePool *) this);
  4279.     }
  4280.  
  4281.     inline AstSwitchStatement *NewSwitchStatement()
  4282.     {
  4283.         return new (Alloc(sizeof(AstSwitchStatement))) AstSwitchStatement((StoragePool *) this);
  4284.     }
  4285.  
  4286.     inline AstWhileStatement *NewWhileStatement()
  4287.     {
  4288.         return new (Alloc(sizeof(AstWhileStatement))) AstWhileStatement();
  4289.     }
  4290.  
  4291.     inline AstDoStatement *NewDoStatement()
  4292.     {
  4293.         return new (Alloc(sizeof(AstDoStatement))) AstDoStatement();
  4294.     }
  4295.  
  4296.     inline AstForStatement *NewForStatement()
  4297.     {
  4298.         return new (Alloc(sizeof(AstForStatement))) AstForStatement((StoragePool *) this);
  4299.     }
  4300.  
  4301.     inline AstBreakStatement *NewBreakStatement()
  4302.     {
  4303.         return new (Alloc(sizeof(AstBreakStatement))) AstBreakStatement();
  4304.     }
  4305.  
  4306.     inline AstContinueStatement *NewContinueStatement()
  4307.     {
  4308.         return new (Alloc(sizeof(AstContinueStatement))) AstContinueStatement();
  4309.     }
  4310.  
  4311.     inline AstReturnStatement *NewReturnStatement()
  4312.     {
  4313.         return new (Alloc(sizeof(AstReturnStatement))) AstReturnStatement();
  4314.     }
  4315.  
  4316.     inline AstThrowStatement *NewThrowStatement()
  4317.     {
  4318.         return new (Alloc(sizeof(AstThrowStatement))) AstThrowStatement();
  4319.     }
  4320.  
  4321.     inline AstSynchronizedStatement *NewSynchronizedStatement()
  4322.     {
  4323.         return new (Alloc(sizeof(AstSynchronizedStatement))) AstSynchronizedStatement();
  4324.     }
  4325.  
  4326.     inline AstCatchClause *NewCatchClause()
  4327.     {
  4328.         return new (Alloc(sizeof(AstCatchClause))) AstCatchClause();
  4329.     }
  4330.  
  4331.     inline AstFinallyClause *NewFinallyClause()
  4332.     {
  4333.         return new (Alloc(sizeof(AstFinallyClause))) AstFinallyClause();
  4334.     }
  4335.  
  4336.     inline AstTryStatement *NewTryStatement()
  4337.     {
  4338.         return new (Alloc(sizeof(AstTryStatement))) AstTryStatement((StoragePool *) this);
  4339.     }
  4340.  
  4341.     inline AstIntegerLiteral *NewIntegerLiteral(LexStream::TokenIndex token)
  4342.     {
  4343.         return new (Alloc(sizeof(AstIntegerLiteral))) AstIntegerLiteral(token);
  4344.     }
  4345.  
  4346.     inline AstLongLiteral *NewLongLiteral(LexStream::TokenIndex token)
  4347.     {
  4348.         return new (Alloc(sizeof(AstLongLiteral))) AstLongLiteral(token);
  4349.     }
  4350.  
  4351.     inline AstFloatingPointLiteral *NewFloatingPointLiteral(LexStream::TokenIndex token)
  4352.     {
  4353.         return new (Alloc(sizeof(AstFloatingPointLiteral))) AstFloatingPointLiteral(token);
  4354.     }
  4355.  
  4356.     inline AstDoubleLiteral *NewDoubleLiteral(LexStream::TokenIndex token)
  4357.     {
  4358.         return new (Alloc(sizeof(AstDoubleLiteral))) AstDoubleLiteral(token);
  4359.     }
  4360.  
  4361.     inline AstTrueLiteral *NewTrueLiteral(LexStream::TokenIndex token)
  4362.     {
  4363.         return new (Alloc(sizeof(AstTrueLiteral))) AstTrueLiteral(token);
  4364.     }
  4365.  
  4366.     inline AstFalseLiteral *NewFalseLiteral(LexStream::TokenIndex token)
  4367.     {
  4368.         return new (Alloc(sizeof(AstFalseLiteral))) AstFalseLiteral(token);
  4369.     }
  4370.  
  4371.     inline AstStringLiteral *NewStringLiteral(LexStream::TokenIndex token)
  4372.     {
  4373.         return new (Alloc(sizeof(AstStringLiteral))) AstStringLiteral(token);
  4374.     }
  4375.  
  4376.     inline AstCharacterLiteral *NewCharacterLiteral(LexStream::TokenIndex token)
  4377.     {
  4378.         return new (Alloc(sizeof(AstCharacterLiteral))) AstCharacterLiteral(token);
  4379.     }
  4380.  
  4381.     inline AstNullLiteral *NewNullLiteral(LexStream::TokenIndex token)
  4382.     {
  4383.         return new (Alloc(sizeof(AstNullLiteral))) AstNullLiteral(token);
  4384.     }
  4385.  
  4386.     inline AstThisExpression *NewThisExpression(LexStream::TokenIndex token)
  4387.     {
  4388.         return new (Alloc(sizeof(AstThisExpression))) AstThisExpression(token);
  4389.     }
  4390.  
  4391.     inline AstSuperExpression *NewSuperExpression(LexStream::TokenIndex token)
  4392.     {
  4393.         return new (Alloc(sizeof(AstSuperExpression))) AstSuperExpression(token);
  4394.     }
  4395.  
  4396.     inline AstParenthesizedExpression *NewParenthesizedExpression()
  4397.     {
  4398.         return new (Alloc(sizeof(AstParenthesizedExpression))) AstParenthesizedExpression();
  4399.     }
  4400.  
  4401.     inline AstTypeExpression *NewTypeExpression(Ast *type)
  4402.     {
  4403.         return new (Alloc(sizeof(AstTypeExpression))) AstTypeExpression(type);
  4404.     }
  4405.  
  4406.     inline AstClassInstanceCreationExpression *NewClassInstanceCreationExpression()
  4407.     {
  4408.         return new (Alloc(sizeof(AstClassInstanceCreationExpression))) AstClassInstanceCreationExpression((StoragePool *) this);
  4409.     }
  4410.  
  4411.     inline AstDimExpr *NewDimExpr()
  4412.     {
  4413.         return new (Alloc(sizeof(AstDimExpr))) AstDimExpr();
  4414.     }
  4415.  
  4416.     inline AstArrayCreationExpression *NewArrayCreationExpression()
  4417.     {
  4418.         return new (Alloc(sizeof(AstArrayCreationExpression))) AstArrayCreationExpression((StoragePool *) this);
  4419.     }
  4420.  
  4421.     inline AstFieldAccess *NewFieldAccess(AstFieldAccess::FieldAccessTag tag = AstFieldAccess::NONE)
  4422.     {
  4423.         return new (Alloc(sizeof(AstFieldAccess))) AstFieldAccess(tag);
  4424.     }
  4425.  
  4426.     inline AstMethodInvocation *NewMethodInvocation()
  4427.     {
  4428.         return new (Alloc(sizeof(AstMethodInvocation))) AstMethodInvocation((StoragePool *) this);
  4429.     }
  4430.  
  4431.     inline AstArrayAccess *NewArrayAccess()
  4432.     {
  4433.         return new (Alloc(sizeof(AstArrayAccess))) AstArrayAccess();
  4434.     }
  4435.  
  4436.     inline AstPostUnaryExpression *NewPostUnaryExpression(AstPostUnaryExpression::PostUnaryExpressionTag tag)
  4437.     {
  4438.         return new (Alloc(sizeof(AstPostUnaryExpression))) AstPostUnaryExpression(tag);
  4439.     }
  4440.  
  4441.     inline AstPreUnaryExpression *NewPreUnaryExpression(AstPreUnaryExpression::PreUnaryExpressionTag tag)
  4442.     {
  4443.         return new (Alloc(sizeof(AstPreUnaryExpression))) AstPreUnaryExpression(tag);
  4444.     }
  4445.  
  4446.     inline AstCastExpression *NewCastExpression()
  4447.     {
  4448.         return new (Alloc(sizeof(AstCastExpression))) AstCastExpression((StoragePool *) this);
  4449.     }
  4450.  
  4451.     inline AstBinaryExpression *NewBinaryExpression(AstBinaryExpression::BinaryExpressionTag tag)
  4452.     {
  4453.         return new (Alloc(sizeof(AstBinaryExpression))) AstBinaryExpression(tag);
  4454.     }
  4455.  
  4456.     inline AstConditionalExpression *NewConditionalExpression()
  4457.     {
  4458.         return new (Alloc(sizeof(AstConditionalExpression))) AstConditionalExpression();
  4459.     }
  4460.  
  4461.     inline AstAssignmentExpression *NewAssignmentExpression(AstAssignmentExpression::AssignmentExpressionTag tag, LexStream::TokenIndex token)
  4462.     {
  4463.         return new (Alloc(sizeof(AstAssignmentExpression))) AstAssignmentExpression(tag, token);
  4464.     }
  4465.  
  4466.     // ********************************************************************************************** //
  4467.  
  4468.     //
  4469.     // Note that CaseElement nodes are always generated.
  4470.     // Since they are not Ast nodes they do not need to
  4471.     // be marked.
  4472.     //
  4473.     inline CaseElement *GenCaseElement()
  4474.     {
  4475.         return new (Alloc(sizeof(CaseElement))) CaseElement();
  4476.     }
  4477.  
  4478.     inline AstBlock *GenBlock()
  4479.     {
  4480.         AstBlock *p = NewBlock();
  4481.         p -> generated = 1;
  4482.         return p;
  4483.     }
  4484.  
  4485.     inline AstPrimitiveType *GenPrimitiveType(Ast::Kind kind, LexStream::TokenIndex token)
  4486.     {
  4487.         AstPrimitiveType *p = NewPrimitiveType(kind, token);
  4488.         p -> generated = 1;
  4489.         return p;
  4490.     }
  4491.  
  4492.     inline AstArrayType *GenArrayType()
  4493.     {
  4494.         AstArrayType *p = NewArrayType();
  4495.         p -> generated = 1;
  4496.         return p;
  4497.     }
  4498.  
  4499.     inline AstSimpleName *GenSimpleName(LexStream::TokenIndex token)
  4500.     {
  4501.         AstSimpleName *p = NewSimpleName(token);
  4502.         p -> generated = 1;
  4503.         return p;
  4504.     }
  4505.  
  4506.     inline AstPackageDeclaration *GenPackageDeclaration()
  4507.     {
  4508.         AstPackageDeclaration *p = NewPackageDeclaration();
  4509.         p -> generated = 1;
  4510.         return p;
  4511.     }
  4512.  
  4513.     inline AstImportDeclaration *GenImportDeclaration()
  4514.     {
  4515.         AstImportDeclaration *p = NewImportDeclaration();
  4516.         p -> generated = 1;
  4517.         return p;
  4518.     }
  4519.  
  4520.     inline AstCompilationUnit *GenCompilationUnit()
  4521.     {
  4522.         AstCompilationUnit *p = NewCompilationUnit();
  4523.         p -> generated = 1;
  4524.         return p;
  4525.     }
  4526.  
  4527.     inline AstModifier *GenModifier(Ast::Kind kind, LexStream::TokenIndex token)
  4528.     {
  4529.         AstModifier *p = NewModifier(kind, token);
  4530.         p -> generated = 1;
  4531.         return p;
  4532.     }
  4533.  
  4534.     inline AstEmptyDeclaration *GenEmptyDeclaration(LexStream::TokenIndex token)
  4535.     {
  4536.         AstEmptyDeclaration *p = NewEmptyDeclaration(token);
  4537.         p -> generated = 1;
  4538.         return p;
  4539.     }
  4540.  
  4541.     inline AstClassBody *GenClassBody()
  4542.     {
  4543.         AstClassBody *p = NewClassBody();
  4544.         p -> generated = 1;
  4545.         return p;
  4546.     }
  4547.  
  4548.     inline AstClassDeclaration *GenClassDeclaration()
  4549.     {
  4550.         AstClassDeclaration *p = NewClassDeclaration();
  4551.         p -> generated = 1;
  4552.         return p;
  4553.     }
  4554.  
  4555.     inline AstArrayInitializer *GenArrayInitializer()
  4556.     {
  4557.         AstArrayInitializer *p = NewArrayInitializer();
  4558.         p -> generated = 1;
  4559.         return p;
  4560.     }
  4561.  
  4562.     inline AstBrackets *GenBrackets(LexStream::TokenIndex left, LexStream::TokenIndex right)
  4563.     {
  4564.         AstBrackets *p = NewBrackets(left, right);
  4565.         p -> generated = 1;
  4566.         return p;
  4567.     }
  4568.  
  4569.     inline AstVariableDeclaratorId *GenVariableDeclaratorId()
  4570.     {
  4571.         AstVariableDeclaratorId *p = NewVariableDeclaratorId();
  4572.         p -> generated = 1;
  4573.         return p;
  4574.     }
  4575.  
  4576.     inline AstVariableDeclarator *GenVariableDeclarator()
  4577.     {
  4578.         AstVariableDeclarator *p = NewVariableDeclarator();
  4579.         p -> generated = 1;
  4580.         return p;
  4581.     }
  4582.  
  4583.     inline AstFieldDeclaration *GenFieldDeclaration()
  4584.     {
  4585.         AstFieldDeclaration *p = NewFieldDeclaration();
  4586.         p -> generated = 1;
  4587.         return p;
  4588.     }
  4589.  
  4590.     inline AstFormalParameter *GenFormalParameter()
  4591.     {
  4592.         AstFormalParameter *p = NewFormalParameter();
  4593.         p -> generated = 1;
  4594.         return p;
  4595.     }
  4596.  
  4597.     inline AstMethodDeclarator *GenMethodDeclarator()
  4598.     {
  4599.         AstMethodDeclarator *p = NewMethodDeclarator();
  4600.         p -> generated = 1;
  4601.         return p;
  4602.     }
  4603.  
  4604.     inline AstMethodDeclaration *GenMethodDeclaration()
  4605.     {
  4606.         AstMethodDeclaration *p = NewMethodDeclaration();
  4607.         p -> generated = 1;
  4608.         return p;
  4609.     }
  4610.  
  4611.     inline AstStaticInitializer *GenStaticInitializer()
  4612.     {
  4613.         AstStaticInitializer *p = NewStaticInitializer();
  4614.         p -> generated = 1;
  4615.         return p;
  4616.     }
  4617.  
  4618.     inline AstThisCall *GenThisCall()
  4619.     {
  4620.         AstThisCall *p = NewThisCall();
  4621.         p -> generated = 1;
  4622.         return p;
  4623.     }
  4624.  
  4625.     inline AstSuperCall *GenSuperCall()
  4626.     {
  4627.         AstSuperCall *p = NewSuperCall();
  4628.         p -> generated = 1;
  4629.         return p;
  4630.     }
  4631.  
  4632.     inline AstConstructorBlock *GenConstructorBlock()
  4633.     {
  4634.         AstConstructorBlock *p = NewConstructorBlock();
  4635.         p -> generated = 1;
  4636.         return p;
  4637.     }
  4638.  
  4639.     inline AstConstructorDeclaration *GenConstructorDeclaration()
  4640.     {
  4641.         AstConstructorDeclaration *p = NewConstructorDeclaration();
  4642.         p -> generated = 1;
  4643.         return p;
  4644.     }
  4645.  
  4646.     inline AstInterfaceDeclaration *GenInterfaceDeclaration()
  4647.     {
  4648.         AstInterfaceDeclaration *p = NewInterfaceDeclaration();
  4649.         p -> generated = 1;
  4650.         return p;
  4651.     }
  4652.  
  4653.     inline AstLocalVariableDeclarationStatement *GenLocalVariableDeclarationStatement()
  4654.     {
  4655.         AstLocalVariableDeclarationStatement *p = NewLocalVariableDeclarationStatement();
  4656.         p -> generated = 1;
  4657.         return p;
  4658.     }
  4659.  
  4660.     inline AstIfStatement *GenIfStatement()
  4661.     {
  4662.         AstIfStatement *p = NewIfStatement();
  4663.         p -> generated = 1;
  4664.         return p;
  4665.     }
  4666.  
  4667.     inline AstEmptyStatement *GenEmptyStatement(LexStream::TokenIndex token)
  4668.     {
  4669.         AstEmptyStatement *p = NewEmptyStatement(token);
  4670.         p -> generated = 1;
  4671.         return p;
  4672.     }
  4673.  
  4674.     inline AstExpressionStatement *GenExpressionStatement()
  4675.     {
  4676.         AstExpressionStatement *p = NewExpressionStatement();
  4677.         p -> generated = 1;
  4678.         return p;
  4679.     }
  4680.  
  4681.     inline AstCaseLabel *GenCaseLabel()
  4682.     {
  4683.         AstCaseLabel *p = NewCaseLabel();
  4684.         p -> generated = 1;
  4685.         return p;
  4686.     }
  4687.  
  4688.     inline AstDefaultLabel *GenDefaultLabel()
  4689.     {
  4690.         AstDefaultLabel *p = NewDefaultLabel();
  4691.         p -> generated = 1;
  4692.         return p;
  4693.     }
  4694.  
  4695.     inline AstSwitchBlockStatement *GenSwitchBlockStatement()
  4696.     {
  4697.         AstSwitchBlockStatement *p = NewSwitchBlockStatement();
  4698.         p -> generated = 1;
  4699.         return p;
  4700.     }
  4701.  
  4702.     inline AstSwitchStatement *GenSwitchStatement()
  4703.     {
  4704.         AstSwitchStatement *p = NewSwitchStatement();
  4705.         p -> generated = 1;
  4706.         return p;
  4707.     }
  4708.  
  4709.     inline AstWhileStatement *GenWhileStatement()
  4710.     {
  4711.         AstWhileStatement *p = NewWhileStatement();
  4712.         p -> generated = 1;
  4713.         return p;
  4714.     }
  4715.  
  4716.     inline AstDoStatement *GenDoStatement()
  4717.     {
  4718.         AstDoStatement *p = NewDoStatement();
  4719.         p -> generated = 1;
  4720.         return p;
  4721.     }
  4722.  
  4723.     inline AstForStatement *GenForStatement()
  4724.     {
  4725.         AstForStatement *p = NewForStatement();
  4726.         p -> generated = 1;
  4727.         return p;
  4728.     }
  4729.  
  4730.     inline AstBreakStatement *GenBreakStatement()
  4731.     {
  4732.         AstBreakStatement *p = NewBreakStatement();
  4733.         p -> generated = 1;
  4734.         return p;
  4735.     }
  4736.  
  4737.     inline AstContinueStatement *GenContinueStatement()
  4738.     {
  4739.         AstContinueStatement *p = NewContinueStatement();
  4740.         p -> generated = 1;
  4741.         return p;
  4742.     }
  4743.  
  4744.     inline AstReturnStatement *GenReturnStatement()
  4745.     {
  4746.         AstReturnStatement *p = NewReturnStatement();
  4747.         p -> generated = 1;
  4748.         return p;
  4749.     }
  4750.  
  4751.     inline AstThrowStatement *GenThrowStatement()
  4752.     {
  4753.         AstThrowStatement *p = NewThrowStatement();
  4754.         p -> generated = 1;
  4755.         return p;
  4756.     }
  4757.  
  4758.     inline AstSynchronizedStatement *GenSynchronizedStatement()
  4759.     {
  4760.         AstSynchronizedStatement *p = NewSynchronizedStatement();
  4761.         p -> generated = 1;
  4762.         return p;
  4763.     }
  4764.  
  4765.     inline AstCatchClause *GenCatchClause()
  4766.     {
  4767.         AstCatchClause *p = NewCatchClause();
  4768.         p -> generated = 1;
  4769.         return p;
  4770.     }
  4771.  
  4772.     inline AstFinallyClause *GenFinallyClause()
  4773.     {
  4774.         AstFinallyClause *p = NewFinallyClause();
  4775.         p -> generated = 1;
  4776.         return p;
  4777.     }
  4778.  
  4779.     inline AstTryStatement *GenTryStatement()
  4780.     {
  4781.         AstTryStatement *p = NewTryStatement();
  4782.         p -> generated = 1;
  4783.         return p;
  4784.     }
  4785.  
  4786.     inline AstIntegerLiteral *GenIntegerLiteral(LexStream::TokenIndex token)
  4787.     {
  4788.         AstIntegerLiteral *p = NewIntegerLiteral(token);
  4789.         p -> generated = 1;
  4790.         return p;
  4791.     }
  4792.  
  4793.     inline AstLongLiteral *GenLongLiteral(LexStream::TokenIndex token)
  4794.     {
  4795.         AstLongLiteral *p = NewLongLiteral(token);
  4796.         p -> generated = 1;
  4797.         return p;
  4798.     }
  4799.  
  4800.     inline AstFloatingPointLiteral *GenFloatingPointLiteral(LexStream::TokenIndex token)
  4801.     {
  4802.         AstFloatingPointLiteral *p = NewFloatingPointLiteral(token);
  4803.         p -> generated = 1;
  4804.         return p;
  4805.     }
  4806.  
  4807.     inline AstDoubleLiteral *GenDoubleLiteral(LexStream::TokenIndex token)
  4808.     {
  4809.         AstDoubleLiteral *p = NewDoubleLiteral(token);
  4810.         p -> generated = 1;
  4811.         return p;
  4812.     }
  4813.  
  4814.     inline AstTrueLiteral *GenTrueLiteral(LexStream::TokenIndex token)
  4815.     {
  4816.         AstTrueLiteral *p = NewTrueLiteral(token);
  4817.         p -> generated = 1;
  4818.         return p;
  4819.     }
  4820.  
  4821.     inline AstFalseLiteral *GenFalseLiteral(LexStream::TokenIndex token)
  4822.     {
  4823.         AstFalseLiteral *p = NewFalseLiteral(token);
  4824.         p -> generated = 1;
  4825.         return p;
  4826.     }
  4827.  
  4828.     inline AstStringLiteral *GenStringLiteral(LexStream::TokenIndex token)
  4829.     {
  4830.         AstStringLiteral *p = NewStringLiteral(token);
  4831.         p -> generated = 1;
  4832.         return p;
  4833.     }
  4834.  
  4835.     inline AstCharacterLiteral *GenCharacterLiteral(LexStream::TokenIndex token)
  4836.     {
  4837.         AstCharacterLiteral *p = NewCharacterLiteral(token);
  4838.         p -> generated = 1;
  4839.         return p;
  4840.     }
  4841.  
  4842.     inline AstNullLiteral *GenNullLiteral(LexStream::TokenIndex token)
  4843.     {
  4844.         AstNullLiteral *p = NewNullLiteral(token);
  4845.         p -> generated = 1;
  4846.         return p;
  4847.     }
  4848.  
  4849.     inline AstThisExpression *GenThisExpression(LexStream::TokenIndex token)
  4850.     {
  4851.         AstThisExpression *p = NewThisExpression(token);
  4852.         p -> generated = 1;
  4853.         return p;
  4854.     }
  4855.  
  4856.     inline AstSuperExpression *GenSuperExpression(LexStream::TokenIndex token)
  4857.     {
  4858.         AstSuperExpression *p = NewSuperExpression(token);
  4859.         p -> generated = 1;
  4860.         return p;
  4861.     }
  4862.  
  4863.     inline AstParenthesizedExpression *GenParenthesizedExpression()
  4864.     {
  4865.         AstParenthesizedExpression *p = NewParenthesizedExpression();
  4866.         p -> generated = 1;
  4867.         return p;
  4868.     }
  4869.  
  4870.     inline AstTypeExpression *GenTypeExpression(Ast *type)
  4871.     {
  4872.         AstTypeExpression *p = NewTypeExpression(type);
  4873.         p -> generated = 1;
  4874.         return p;
  4875.     }
  4876.  
  4877.     inline AstClassInstanceCreationExpression *GenClassInstanceCreationExpression()
  4878.     {
  4879.         AstClassInstanceCreationExpression *p = NewClassInstanceCreationExpression();
  4880.         p -> generated = 1;
  4881.         return p;
  4882.     }
  4883.  
  4884.     inline AstDimExpr *GenDimExpr()
  4885.     {
  4886.         AstDimExpr *p = NewDimExpr();
  4887.         p -> generated = 1;
  4888.         return p;
  4889.     }
  4890.  
  4891.     inline AstArrayCreationExpression *GenArrayCreationExpression()
  4892.     {
  4893.         AstArrayCreationExpression *p = NewArrayCreationExpression();
  4894.         p -> generated = 1;
  4895.         return p;
  4896.     }
  4897.  
  4898.     inline AstFieldAccess *GenFieldAccess(AstFieldAccess::FieldAccessTag tag = AstFieldAccess::NONE)
  4899.     {
  4900.         AstFieldAccess *p = NewFieldAccess(tag);
  4901.         p -> generated = 1;
  4902.         return p;
  4903.     }
  4904.  
  4905.     inline AstMethodInvocation *GenMethodInvocation()
  4906.     {
  4907.         AstMethodInvocation *p = NewMethodInvocation();
  4908.         p -> generated = 1;
  4909.         return p;
  4910.     }
  4911.  
  4912.     inline AstArrayAccess *GenArrayAccess()
  4913.     {
  4914.         AstArrayAccess *p = NewArrayAccess();
  4915.         p -> generated = 1;
  4916.         return p;
  4917.     }
  4918.  
  4919.     inline AstPostUnaryExpression *GenPostUnaryExpression(AstPostUnaryExpression::PostUnaryExpressionTag tag)
  4920.     {
  4921.         AstPostUnaryExpression *p = NewPostUnaryExpression(tag);
  4922.         p -> generated = 1;
  4923.         return p;
  4924.     }
  4925.  
  4926.     inline AstPreUnaryExpression *GenPreUnaryExpression(AstPreUnaryExpression::PreUnaryExpressionTag tag)
  4927.     {
  4928.         AstPreUnaryExpression *p = NewPreUnaryExpression(tag);
  4929.         p -> generated = 1;
  4930.         return p;
  4931.     }
  4932.  
  4933.     inline AstCastExpression *GenCastExpression()
  4934.     {
  4935.         AstCastExpression *p = NewCastExpression();
  4936.         p -> generated = 1;
  4937.         return p;
  4938.     }
  4939.  
  4940.     inline AstBinaryExpression *GenBinaryExpression(AstBinaryExpression::BinaryExpressionTag tag)
  4941.     {
  4942.         AstBinaryExpression *p = NewBinaryExpression(tag);
  4943.         p -> generated = 1;
  4944.         return p;
  4945.     }
  4946.  
  4947.     inline AstConditionalExpression *GenConditionalExpression()
  4948.     {
  4949.         AstConditionalExpression *p = NewConditionalExpression();
  4950.         p -> generated = 1;
  4951.         return p;
  4952.     }
  4953.  
  4954.     inline AstAssignmentExpression *GenAssignmentExpression(AstAssignmentExpression::AssignmentExpressionTag tag, LexStream::TokenIndex token)
  4955.     {
  4956.         AstAssignmentExpression *p = NewAssignmentExpression(tag, token);
  4957.         p -> generated = 1;
  4958.         return p;
  4959.     }
  4960.  
  4961.  
  4962.     // ********************************************************************************************** //
  4963.  
  4964.     //
  4965.     // Return the total size of temporary space allocated.
  4966.     //
  4967.     size_t SpaceAllocated(void)
  4968.     {
  4969.         return ((base_size * sizeof(Cell **)) + (size * sizeof(Cell)));
  4970.     }
  4971.  
  4972.     //
  4973.     // Return the total size of temporary space used.
  4974.     //
  4975.     size_t SpaceUsed(void)
  4976.     {
  4977.         return (((size >> log_blksize) * sizeof(Cell **)) + (top * sizeof(Cell)));
  4978.     }
  4979. };
  4980.  
  4981. inline void AstClassBody::AllocateInstanceVariables(int estimate)
  4982. {
  4983.     if (! instance_variables)
  4984.         instance_variables = (AstArray<AstFieldDeclaration *> *) pool -> NewAstArray(estimate);
  4985. }
  4986.  
  4987. inline void AstClassBody::AddInstanceVariable(AstFieldDeclaration *field_declaration)
  4988. {
  4989.     if (! instance_variables)
  4990.         instance_variables = (AstArray<AstFieldDeclaration *> *) pool -> NewAstArray();
  4991.     instance_variables -> Next() = field_declaration;
  4992. }
  4993.  
  4994. inline void AstClassBody::AllocateClassVariables(int estimate)
  4995. {
  4996.     if (! class_variables)
  4997.         class_variables = (AstArray<AstFieldDeclaration *> *) pool -> NewAstArray(estimate);
  4998. }
  4999.  
  5000. inline void AstClassBody::AddClassVariable(AstFieldDeclaration *field_declaration)
  5001. {
  5002.     if (! class_variables)
  5003.         class_variables = (AstArray<AstFieldDeclaration *> *) pool -> NewAstArray();
  5004.     class_variables -> Next() = field_declaration;
  5005. }
  5006.  
  5007. inline void AstClassBody::AllocateMethods(int estimate)
  5008. {
  5009.     if (! methods)
  5010.         methods = (AstArray<AstMethodDeclaration *> *) pool -> NewAstArray(estimate);
  5011. }
  5012.  
  5013. inline void AstClassBody::AddMethod(AstMethodDeclaration *method_declaration)
  5014. {
  5015.     if (! methods)
  5016.         methods = (AstArray<AstMethodDeclaration *> *) pool -> NewAstArray();
  5017.     methods -> Next() = method_declaration;
  5018. }
  5019.  
  5020. inline void AstClassBody::AllocateBlocks(int estimate)
  5021. {
  5022.     if (! blocks)
  5023.         blocks = (AstArray<AstBlock *> *) pool -> NewAstArray(estimate);
  5024. }
  5025.  
  5026. inline void AstClassBody::AddBlock(AstBlock *block)
  5027. {
  5028.     if (! blocks)
  5029.         blocks = (AstArray<AstBlock *> *) pool -> NewAstArray();
  5030.     blocks -> Next() = block;
  5031. }
  5032.  
  5033. inline void AstClassBody::AllocateNestedInterfaces(int estimate)
  5034. {
  5035.     if (! inner_interfaces)
  5036.         inner_interfaces = (AstArray<AstInterfaceDeclaration *> *) pool -> NewAstArray(estimate);
  5037. }
  5038.  
  5039. inline void AstClassBody::AddNestedInterface(AstInterfaceDeclaration *interface_declaration)
  5040. {
  5041.     if (! inner_interfaces)
  5042.         inner_interfaces = (AstArray<AstInterfaceDeclaration *> *) pool -> NewAstArray();
  5043.     inner_interfaces -> Next() = interface_declaration;
  5044. }
  5045.  
  5046. inline void AstClassBody::AllocateNestedClasses(int estimate)
  5047. {
  5048.     if (! inner_classes)
  5049.         inner_classes = (AstArray<AstClassDeclaration *> *) pool -> NewAstArray(estimate);
  5050. }
  5051.  
  5052. inline void AstClassBody::AddNestedClass(AstClassDeclaration *class_declaration)
  5053. {
  5054.     if (! inner_classes)
  5055.         inner_classes = (AstArray<AstClassDeclaration *> *) pool -> NewAstArray();
  5056.     inner_classes -> Next() = class_declaration;
  5057. }
  5058.  
  5059. inline void AstClassBody::AllocateStaticInitializers(int estimate)
  5060. {
  5061.     if (! static_initializers)
  5062.         static_initializers = (AstArray<AstStaticInitializer *> *) pool -> NewAstArray(estimate);
  5063. }
  5064.  
  5065. inline void AstClassBody::AddStaticInitializer(AstStaticInitializer *static_initializer)
  5066. {
  5067.     if (! static_initializers)
  5068.         static_initializers = (AstArray<AstStaticInitializer *> *) pool -> NewAstArray();
  5069.     static_initializers -> Next() = static_initializer;
  5070. }
  5071.  
  5072. inline void AstClassBody::AllocateConstructors(int estimate)
  5073. {
  5074.     if (! constructors)
  5075.         constructors = (AstArray<AstConstructorDeclaration *> *) pool -> NewAstArray(estimate);
  5076. }
  5077.  
  5078. inline void AstClassBody::AddConstructor(AstConstructorDeclaration *constructor_declaration)
  5079. {
  5080.     if (! constructors)
  5081.         constructors = (AstArray<AstConstructorDeclaration *> *) pool -> NewAstArray();
  5082.     constructors -> Next() = constructor_declaration;
  5083. }
  5084.  
  5085. inline void AstClassBody::AllocateEmptyDeclarations(int estimate)
  5086. {
  5087.     if (! empty_declarations)
  5088.         empty_declarations = (AstArray<AstEmptyDeclaration *> *) pool -> NewAstArray(estimate);
  5089. }
  5090.  
  5091. inline void AstClassBody::AddEmptyDeclaration(AstEmptyDeclaration *empty_declaration)
  5092. {
  5093.     if (! empty_declarations)
  5094.         empty_declarations = (AstArray<AstEmptyDeclaration *> *) pool -> NewAstArray();
  5095.     empty_declarations -> Next() = empty_declaration;
  5096. }
  5097.  
  5098. inline void AstInterfaceDeclaration::AllocateNestedInterfaces(int estimate)
  5099. {
  5100.     if (! inner_interfaces)
  5101.         inner_interfaces = (AstArray<AstInterfaceDeclaration *> *) pool -> NewAstArray(estimate);
  5102. }
  5103.  
  5104. inline void AstInterfaceDeclaration::AddNestedInterface(AstInterfaceDeclaration *interface_declaration)
  5105. {
  5106.     if (! inner_interfaces)
  5107.         inner_interfaces = (AstArray<AstInterfaceDeclaration *> *) pool -> NewAstArray();
  5108.     inner_interfaces -> Next() = interface_declaration;
  5109. }
  5110.  
  5111. inline void AstInterfaceDeclaration::AllocateNestedClasses(int estimate)
  5112. {
  5113.     if (! inner_classes)
  5114.         inner_classes = (AstArray<AstClassDeclaration *> *) pool -> NewAstArray(estimate);
  5115. }
  5116.  
  5117. inline void AstInterfaceDeclaration::AddNestedClass(AstClassDeclaration *class_declaration)
  5118. {
  5119.     if (! inner_classes)
  5120.         inner_classes = (AstArray<AstClassDeclaration *> *) pool -> NewAstArray();
  5121.     inner_classes -> Next() = class_declaration;
  5122. }
  5123.  
  5124. inline void AstInterfaceDeclaration::AllocateMethods(int estimate)
  5125. {
  5126.     if (! methods)
  5127.         methods = (AstArray<AstMethodDeclaration *> *) pool -> NewAstArray(estimate);
  5128. }
  5129.  
  5130. inline void AstInterfaceDeclaration::AddMethod(AstMethodDeclaration *method_declaration)
  5131. {
  5132.     if (! methods)
  5133.         methods = (AstArray<AstMethodDeclaration *> *) pool -> NewAstArray();
  5134.     methods -> Next() = method_declaration;
  5135. }
  5136.  
  5137. inline void AstInterfaceDeclaration::AllocateClassVariables(int estimate)
  5138. {
  5139.     if (! class_variables)
  5140.         class_variables = (AstArray<AstFieldDeclaration *> *) pool -> NewAstArray(estimate);
  5141. }
  5142.  
  5143. inline void AstInterfaceDeclaration::AddClassVariable(AstFieldDeclaration *field_declaration)
  5144. {
  5145.     if (! class_variables)
  5146.         class_variables = (AstArray<AstFieldDeclaration *> *) pool -> NewAstArray();
  5147.     class_variables -> Next() = field_declaration;
  5148. }
  5149.  
  5150. inline void AstInterfaceDeclaration::AllocateEmptyDeclarations(int estimate)
  5151. {
  5152.     if (! empty_declarations)
  5153.         empty_declarations = (AstArray<AstEmptyDeclaration *> *) pool -> NewAstArray(estimate);
  5154. }
  5155.  
  5156. inline void AstInterfaceDeclaration::AddEmptyDeclaration(AstEmptyDeclaration *empty_declaration)
  5157. {
  5158.     if (! empty_declarations)
  5159.         empty_declarations = (AstArray<AstEmptyDeclaration *> *) pool -> NewAstArray();
  5160.     empty_declarations -> Next() = empty_declaration;
  5161. }
  5162.  
  5163. inline void AstClassDeclaration::AllocateClassModifiers(int estimate)
  5164. {
  5165.     if (! class_modifiers)
  5166.         class_modifiers = (AstArray<AstModifier *> *) pool -> NewAstArray(estimate);
  5167. }
  5168.  
  5169. inline void AstClassDeclaration::AddClassModifier(AstModifier *class_modifier)
  5170. {
  5171.     if (! class_modifiers)
  5172.         AllocateClassModifiers(4); // there are only 10 modifiers.
  5173.     class_modifiers -> Next() = class_modifier;
  5174. }
  5175.  
  5176. inline void AstFieldDeclaration::AllocateVariableModifiers(int estimate)
  5177. {
  5178.     if (! variable_modifiers)
  5179.         variable_modifiers = (AstArray<AstModifier *> *) pool -> NewAstArray(estimate);
  5180. }
  5181.  
  5182. inline void AstFieldDeclaration::AddVariableModifier(AstModifier *variable_modifier)
  5183. {
  5184.     if (! variable_modifiers)
  5185.         AllocateVariableModifiers(4); // there are only 10 modifiers.
  5186.     variable_modifiers -> Next() = variable_modifier;
  5187. }
  5188.  
  5189. inline void AstFormalParameter::AllocateParameterModifiers(int estimate)
  5190. {
  5191.     if (! parameter_modifiers)
  5192.         parameter_modifiers = (AstArray<AstModifier *> *) pool -> NewAstArray(estimate);
  5193. }
  5194.  
  5195. inline void AstFormalParameter::AddParameterModifier(AstModifier *parameter_modifier)
  5196. {
  5197.     if (! parameter_modifiers)
  5198.         AllocateParameterModifiers(4); // there are only 10 modifiers.
  5199.     parameter_modifiers -> Next() = parameter_modifier;
  5200. }
  5201.  
  5202. inline void AstMethodDeclaration::AllocateMethodModifiers(int estimate)
  5203. {
  5204.     if (! method_modifiers)
  5205.         method_modifiers = (AstArray<AstModifier *> *) pool -> NewAstArray(estimate);
  5206. }
  5207.  
  5208. inline void AstMethodDeclaration::AddMethodModifier(AstModifier *method_modifier)
  5209. {
  5210.     if (! method_modifiers)
  5211.         AllocateMethodModifiers(4); // there are only 10 modifiers.
  5212.     method_modifiers -> Next() = method_modifier;
  5213. }
  5214.  
  5215. inline void AstConstructorDeclaration::AllocateConstructorModifiers(int estimate)
  5216. {
  5217.     if (! constructor_modifiers)
  5218.         constructor_modifiers = (AstArray<AstModifier *> *) pool -> NewAstArray(estimate);
  5219. }
  5220.  
  5221. inline void AstConstructorDeclaration::AddConstructorModifier(AstModifier *constructor_modifier)
  5222. {
  5223.     if (! constructor_modifiers)
  5224.         AllocateConstructorModifiers(4); // there are only 10 modifiers.
  5225.     constructor_modifiers -> Next() = constructor_modifier;
  5226. }
  5227.  
  5228. inline void AstInterfaceDeclaration::AllocateInterfaceModifiers(int estimate)
  5229. {
  5230.     if (! interface_modifiers)
  5231.         interface_modifiers = (AstArray<AstModifier *> *) pool -> NewAstArray(estimate);
  5232. }
  5233.  
  5234. inline void AstInterfaceDeclaration::AddInterfaceModifier(AstModifier *interface_modifier)
  5235. {
  5236.     if (! interface_modifiers)
  5237.         AllocateInterfaceModifiers(4); // there are only 10 modifiers.
  5238.     interface_modifiers -> Next() = interface_modifier;
  5239. }
  5240.  
  5241. inline void AstLocalVariableDeclarationStatement::AllocateLocalModifiers(int estimate)
  5242. {
  5243.     if (! local_modifiers)
  5244.         local_modifiers = (AstArray<AstModifier *> *) pool -> NewAstArray(estimate);
  5245. }
  5246.  
  5247. inline void AstLocalVariableDeclarationStatement::AddLocalModifier(AstModifier *local_modifier)
  5248. {
  5249.     if (! local_modifiers)
  5250.         AllocateLocalModifiers(4); // there are only 10 modifiers.
  5251.     local_modifiers -> Next() = local_modifier;
  5252. }
  5253.  
  5254. inline void AstBlock::AllocateBlockStatements(int estimate)
  5255. {
  5256.     if (! block_statements)
  5257.         block_statements = pool -> NewAstArray(estimate);
  5258. }
  5259.  
  5260. inline void AstBlock::AddStatement(Ast *statement)
  5261. {
  5262.     if (! block_statements)
  5263.         AllocateBlockStatements();
  5264.     block_statements -> Next() = statement;
  5265. }
  5266.  
  5267. inline void AstBlock::AllocateLabels(int estimate)
  5268. {
  5269.     if (! labels)
  5270.         labels = pool -> NewTokenIndexArray(estimate);
  5271. }
  5272.  
  5273. inline void AstBlock::AddLabel(LexStream::TokenIndex label_token_index)
  5274. {
  5275.     if (! labels)
  5276.         AllocateLabels();
  5277.     labels -> Next() = label_token_index;
  5278. }
  5279.  
  5280. inline void AstSwitchBlockStatement::AllocateBlockStatements(int estimate)
  5281. {
  5282.     if (! block_statements)
  5283.         block_statements = (AstArray<AstStatement *> *) pool -> NewAstArray(estimate);
  5284. }
  5285.  
  5286. inline void AstSwitchBlockStatement::AddStatement(AstStatement *statement)
  5287. {
  5288.     if (! block_statements)
  5289.         AllocateBlockStatements();
  5290.     block_statements -> Next() = statement;
  5291. }
  5292.  
  5293. inline void AstSwitchBlockStatement::AllocateSwitchLabels(int estimate)
  5294. {
  5295.     if (! switch_labels)
  5296.         switch_labels = pool -> NewAstArray(estimate);
  5297. }
  5298.  
  5299. inline void AstSwitchBlockStatement::AddSwitchLabel(Ast *case_or_default_label)
  5300. {
  5301.     if (! switch_labels)
  5302.         AllocateSwitchLabels();
  5303.     switch_labels -> Next() = case_or_default_label;
  5304. }
  5305.  
  5306. inline void AstSwitchStatement::AllocateCases(int estimate)
  5307. {
  5308.     if (! cases)
  5309.         cases = pool -> NewCaseElementArray(estimate);
  5310. }
  5311.  
  5312. inline void AstSwitchStatement::AddCase(CaseElement *case_element)
  5313. {
  5314.     if (! cases)
  5315.         AllocateCases();
  5316.     cases -> Next() = case_element;
  5317. }
  5318.  
  5319. inline void AstConstructorBlock::AllocateLocalInitStatements(int estimate)
  5320. {
  5321.     if (! local_init_statements)
  5322.         local_init_statements = (AstArray<AstStatement *> *) pool -> NewAstArray(estimate);
  5323. }
  5324.  
  5325. inline void AstConstructorBlock::AddLocalInitStatement(AstStatement *statement)
  5326. {
  5327.     if (! local_init_statements)
  5328.         AllocateLocalInitStatements();
  5329.     local_init_statements -> Next() = statement;
  5330. }
  5331.  
  5332. inline void AstVariableDeclaratorId::AllocateBrackets(int estimate)
  5333. {
  5334.     if (! brackets)
  5335.         brackets = (AstArray<AstBrackets *> *) pool -> NewAstArray(estimate);
  5336. }
  5337.  
  5338. inline void AstVariableDeclaratorId::AddBrackets(AstBrackets *bracket)
  5339. {
  5340.     if (! brackets)
  5341.         AllocateBrackets();
  5342.     brackets -> Next() = bracket;
  5343. }
  5344.  
  5345. inline void AstArrayType::AllocateBrackets(int estimate)
  5346. {
  5347.     if (! brackets)
  5348.         brackets = (AstArray<AstBrackets *> *) pool -> NewAstArray(estimate);
  5349. }
  5350.  
  5351. inline void AstArrayType::AddBrackets(AstBrackets *bracket)
  5352. {
  5353.     if (! brackets)
  5354.         AllocateBrackets();
  5355.     brackets -> Next() = bracket;
  5356. }
  5357.  
  5358. inline void AstMethodDeclarator::AllocateBrackets(int estimate)
  5359. {
  5360.     if (! brackets)
  5361.         brackets = (AstArray<AstBrackets *> *) pool -> NewAstArray(estimate);
  5362. }
  5363.  
  5364. inline void AstMethodDeclarator::AddBrackets(AstBrackets *bracket)
  5365. {
  5366.     if (! brackets)
  5367.         AllocateBrackets();
  5368.     brackets -> Next() = bracket;
  5369. }
  5370.  
  5371. inline void AstArrayCreationExpression::AllocateBrackets(int estimate)
  5372. {
  5373.     if (! brackets)
  5374.         brackets = (AstArray<AstBrackets *> *) pool -> NewAstArray(estimate);
  5375. }
  5376.  
  5377. inline void AstArrayCreationExpression::AddBrackets(AstBrackets *bracket)
  5378. {
  5379.     if (! brackets)
  5380.         AllocateBrackets();
  5381.     brackets -> Next() = bracket;
  5382. }
  5383.  
  5384. inline void AstCastExpression::AllocateBrackets(int estimate)
  5385. {
  5386.     if (! brackets)
  5387.         brackets = (AstArray<AstBrackets *> *) pool -> NewAstArray(estimate);
  5388. }
  5389.  
  5390. inline void AstCastExpression::AddBrackets(AstBrackets *bracket)
  5391. {
  5392.     if (! brackets)
  5393.         AllocateBrackets();
  5394.     brackets -> Next() = bracket;
  5395. }
  5396.  
  5397. inline void AstArrayCreationExpression::AllocateDimExprs(int estimate)
  5398. {
  5399.     if (! dim_exprs)
  5400.         dim_exprs = (AstArray<AstDimExpr *> *) pool -> NewAstArray(estimate);
  5401. }
  5402.  
  5403. inline void AstArrayCreationExpression::AddDimExpr(AstDimExpr *dim_expr)
  5404. {
  5405.     if (! dim_exprs)
  5406.         AllocateDimExprs(); // will not be executed as we can assume dim_exprs has already beenallocated
  5407.     dim_exprs -> Next() = dim_expr;
  5408. }
  5409.  
  5410. inline void AstThisCall::AllocateArguments(int estimate)
  5411. {
  5412.     if (! arguments)
  5413.         arguments = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5414. }
  5415.  
  5416. inline void AstThisCall::AddArgument(AstExpression *argument)
  5417. {
  5418.     if (! arguments)
  5419.         AllocateArguments(); // will not be executed as we can assume arguments has already beenallocated
  5420.     arguments -> Next() = argument;
  5421. }
  5422.  
  5423. inline void AstSuperCall::AllocateArguments(int estimate)
  5424. {
  5425.     if (! arguments)
  5426.         arguments = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5427. }
  5428.  
  5429. inline void AstSuperCall::AddArgument(AstExpression *argument)
  5430. {
  5431.     if (! arguments)
  5432.         AllocateArguments(); // will not be executed as we can assume arguments has already beenallocated
  5433.     arguments -> Next() = argument;
  5434. }
  5435.  
  5436. inline void AstClassInstanceCreationExpression::AllocateArguments(int estimate)
  5437. {
  5438.     if (! arguments)
  5439.         arguments = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5440. }
  5441.  
  5442. inline void AstClassInstanceCreationExpression::AddArgument(AstExpression *argument)
  5443. {
  5444.     if (! arguments)
  5445.         AllocateArguments(); // will not be executed as we can assume arguments has already beenallocated
  5446.     arguments -> Next() = argument;
  5447. }
  5448.  
  5449. inline void AstMethodInvocation::AllocateArguments(int estimate)
  5450. {
  5451.     if (! arguments)
  5452.         arguments = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5453. }
  5454.  
  5455. inline void AstMethodInvocation::AddArgument(AstExpression *argument)
  5456. {
  5457.     if (! arguments)
  5458.         AllocateArguments(); // will not be executed as we can assume arguments has already beenallocated
  5459.     arguments -> Next() = argument;
  5460. }
  5461.  
  5462. inline void AstThisCall::AllocateLocalArguments(int estimate)
  5463. {
  5464.     if (! local_arguments_opt)
  5465.         local_arguments_opt = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5466. }
  5467.  
  5468. inline void AstThisCall::AddLocalArgument(AstExpression *argument)
  5469. {
  5470.     if (! local_arguments_opt)
  5471.         AllocateLocalArguments();
  5472.     local_arguments_opt -> Next() = argument;
  5473. }
  5474.  
  5475. inline void AstSuperCall::AllocateLocalArguments(int estimate)
  5476. {
  5477.     if (! local_arguments_opt)
  5478.         local_arguments_opt = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5479. }
  5480.  
  5481. inline void AstSuperCall::AddLocalArgument(AstExpression *argument)
  5482. {
  5483.     if (! local_arguments_opt)
  5484.         AllocateLocalArguments();
  5485.     local_arguments_opt -> Next() = argument;
  5486. }
  5487.  
  5488. inline void AstClassInstanceCreationExpression::AllocateLocalArguments(int estimate)
  5489. {
  5490.     if (! local_arguments_opt)
  5491.         local_arguments_opt = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5492. }
  5493.  
  5494. inline void AstClassInstanceCreationExpression::AddLocalArgument(AstExpression *argument)
  5495. {
  5496.     if (! local_arguments_opt)
  5497.         AllocateLocalArguments();
  5498.     local_arguments_opt -> Next() = argument;
  5499. }
  5500.  
  5501. inline void AstMethodDeclaration::AllocateThrows(int estimate)
  5502. {
  5503.     if (! throws)
  5504.         throws = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5505. }
  5506.  
  5507. inline void AstMethodDeclaration::AddThrow(AstExpression *exception)
  5508. {
  5509.     if (! throws)
  5510.         AllocateThrows();
  5511.     throws -> Next() = exception;
  5512. }
  5513.  
  5514. inline void AstConstructorDeclaration::AllocateThrows(int estimate)
  5515. {
  5516.     if (! throws)
  5517.         throws = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5518. }
  5519.  
  5520. inline void AstConstructorDeclaration::AddThrow(AstExpression *exception)
  5521. {
  5522.     if (! throws)
  5523.         AllocateThrows();
  5524.     throws -> Next() = exception;
  5525. }
  5526.  
  5527. inline void AstMethodDeclarator::AllocateFormalParameters(int estimate)
  5528. {
  5529.     if (! formal_parameters)
  5530.         formal_parameters = (AstArray<AstFormalParameter *> *) pool -> NewAstArray(estimate);
  5531. }
  5532.  
  5533. inline void AstMethodDeclarator::AddFormalParameter(AstFormalParameter *formal_parameter)
  5534. {
  5535.     if (! formal_parameters)
  5536.         AllocateFormalParameters();
  5537.     formal_parameters -> Next() = formal_parameter;
  5538. }
  5539.  
  5540. inline void AstLocalVariableDeclarationStatement::AllocateVariableDeclarators(int estimate)
  5541. {
  5542.     if (! variable_declarators)
  5543.         variable_declarators = (AstArray<AstVariableDeclarator *> *) pool -> NewAstArray(estimate);
  5544. }
  5545.  
  5546. inline void AstLocalVariableDeclarationStatement::AddVariableDeclarator(AstVariableDeclarator *variable_declarator)
  5547. {
  5548.     if (! variable_declarators)
  5549.         AllocateVariableDeclarators();
  5550.     variable_declarators -> Next() = variable_declarator;
  5551. }
  5552.  
  5553. inline void AstFieldDeclaration::AllocateVariableDeclarators(int estimate)
  5554. {
  5555.     if (! variable_declarators)
  5556.         variable_declarators = (AstArray<AstVariableDeclarator *> *) pool -> NewAstArray(estimate);
  5557. }
  5558.  
  5559. inline void AstFieldDeclaration::AddVariableDeclarator(AstVariableDeclarator *variable_declarator)
  5560. {
  5561.     if (! variable_declarators)
  5562.         AllocateVariableDeclarators();
  5563.     variable_declarators -> Next() = variable_declarator;
  5564. }
  5565.  
  5566. inline void AstClassDeclaration::AllocateInterfaces(int estimate)
  5567. {
  5568.     if (! interfaces)
  5569.         interfaces = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5570. }
  5571.  
  5572. inline void AstClassDeclaration::AddInterface(AstExpression *interf)
  5573. {
  5574.     if (! interfaces)
  5575.         AllocateInterfaces();
  5576.     interfaces -> Next() = interf;
  5577. }
  5578.  
  5579. inline void AstInterfaceDeclaration::AllocateExtendsInterfaces(int estimate)
  5580. {
  5581.     if (! extends_interfaces)
  5582.         extends_interfaces = (AstArray<AstExpression *> *) pool -> NewAstArray(estimate);
  5583. }
  5584.  
  5585. inline void AstInterfaceDeclaration::AddExtendsInterface(AstExpression *interf)
  5586. {
  5587.     if (! extends_interfaces)
  5588.         AllocateExtendsInterfaces();
  5589.     extends_interfaces -> Next() = interf;
  5590. }
  5591.  
  5592. inline void AstInterfaceDeclaration::AllocateInterfaceMemberDeclarations(int estimate)
  5593. {
  5594.     if (! interface_member_declarations)
  5595.         interface_member_declarations = pool -> NewAstArray(estimate);
  5596. }
  5597.  
  5598. inline void AstInterfaceDeclaration::AddInterfaceMemberDeclaration(Ast *member)
  5599. {
  5600.     if (! interface_member_declarations)
  5601.         AllocateInterfaceMemberDeclarations();
  5602.     interface_member_declarations -> Next() = member;
  5603. }
  5604.  
  5605. inline void AstClassBody::AllocateClassBodyDeclarations(int estimate)
  5606. {
  5607.     if (! class_body_declarations)
  5608.         class_body_declarations = pool -> NewAstArray(estimate);
  5609. }
  5610.  
  5611. inline void AstClassBody::AddClassBodyDeclaration(Ast *member)
  5612. {
  5613.     if (! class_body_declarations)
  5614.         AllocateClassBodyDeclarations();
  5615.     class_body_declarations -> Next() = member;
  5616. }
  5617.  
  5618. inline void AstForStatement::AllocateForInitStatements(int estimate)
  5619. {
  5620.     if (! for_init_statements)
  5621.         for_init_statements = (AstArray<AstStatement *> *) pool -> NewAstArray(estimate);
  5622. }
  5623.  
  5624. inline void AstForStatement::AddForInitStatement(AstStatement *statement)
  5625. {
  5626.     if (! for_init_statements)
  5627.         AllocateForInitStatements();
  5628.     for_init_statements -> Next() = statement;
  5629. }
  5630.  
  5631. inline void AstForStatement::AllocateForUpdateStatements(int estimate)
  5632. {
  5633.     if (! for_update_statements)
  5634.         for_update_statements = (AstArray<AstExpressionStatement *> *) pool -> NewAstArray(estimate);
  5635. }
  5636.  
  5637. inline void AstForStatement::AddForUpdateStatement(AstExpressionStatement *statement)
  5638. {
  5639.     if (! for_update_statements)
  5640.         AllocateForUpdateStatements();
  5641.     for_update_statements -> Next() = statement;
  5642. }
  5643.  
  5644. inline void AstArrayInitializer::AllocateVariableInitializers(int estimate)
  5645. {
  5646.     if (! variable_initializers)
  5647.         variable_initializers = pool -> NewAstArray(estimate);
  5648. }
  5649.  
  5650. inline void AstArrayInitializer::AddVariableInitializer(Ast *initializer)
  5651. {
  5652.     if (! variable_initializers)
  5653.         AllocateVariableInitializers();
  5654.     variable_initializers -> Next() = initializer;
  5655. }
  5656.  
  5657. inline void AstTryStatement::AllocateCatchClauses(int estimate)
  5658. {
  5659.     if (! catch_clauses)
  5660.         catch_clauses = (AstArray<AstCatchClause *> *) pool -> NewAstArray(estimate);
  5661. }
  5662.  
  5663. inline void AstTryStatement::AddCatchClause(AstCatchClause *catch_clause)
  5664. {
  5665.     if (! catch_clauses)
  5666.         AllocateCatchClauses();
  5667.     catch_clauses -> Next() = catch_clause;
  5668. }
  5669.  
  5670. inline void AstCompilationUnit::AllocateImportDeclarations(int estimate)
  5671. {
  5672.     if (! import_declarations)
  5673.         import_declarations = (AstArray<AstImportDeclaration *> *) pool -> NewAstArray(estimate);
  5674. }
  5675.  
  5676. inline void AstCompilationUnit::AddImportDeclaration(AstImportDeclaration *import_declaration)
  5677. {
  5678.     if (! import_declarations)
  5679.         AllocateImportDeclarations();
  5680.     import_declarations -> Next() = import_declaration;
  5681. }
  5682.  
  5683. inline void AstCompilationUnit::AllocateTypeDeclarations(int estimate)
  5684. {
  5685.     if (! type_declarations)
  5686.         type_declarations = pool -> NewAstArray(estimate);
  5687. }
  5688.  
  5689. inline void AstCompilationUnit::AddTypeDeclaration(Ast *type_declaration)
  5690. {
  5691.     if (! type_declarations)
  5692.         AllocateTypeDeclarations();
  5693.     type_declarations -> Next() = type_declaration;
  5694. }
  5695.  
  5696. //
  5697. // Allocate another block of storage for the ast array.
  5698. //
  5699. template <class T>
  5700.     void AstArray<T>::AllocateMoreSpace()
  5701.     {
  5702.         //
  5703.         //
  5704.         // The variable size always indicates the maximum number of
  5705.         // elements that has been allocated for the array.
  5706.         // Initially, it is set to 0 to indicate that the array is empty.
  5707.         // The pool of available elements is divided into segments of size
  5708.         // 2**log_blksize each. Each segment is pointed to by a slot in
  5709.         // the array base.
  5710.         //
  5711.         // By dividing size by the size of the segment we obtain the
  5712.         // index for the next segment in base. If base is full, it is
  5713.         // reallocated.
  5714.         //
  5715.         //
  5716.         int k = size >> log_blksize; /* which segment? */
  5717.  
  5718.         //
  5719.         // If the base is overflowed, reallocate it and initialize the new elements to NULL.
  5720.         //
  5721.         if (k == base_size)
  5722.         {
  5723.             int old_base_size = base_size;
  5724.             T **old_base = base;
  5725.  
  5726.             base_size += base_increment;
  5727.  
  5728.             assert(base_size <= pool -> Blksize()); // There must be enough room to allocate base
  5729.  
  5730.             base = (T **) pool -> Alloc(sizeof(T *) * base_size);
  5731.  
  5732.             if (old_base != NULL)
  5733.             {
  5734.                 memmove(base, old_base, old_base_size * sizeof(T *));
  5735. // STG:
  5736. //                delete [] old_base;
  5737.             }
  5738.             memset(&base[old_base_size], 0, (base_size - old_base_size) * sizeof(T *));
  5739.         }
  5740.  
  5741.         //
  5742.         // We allocate a new segment and place its adjusted address in
  5743.         // base[k]. The adjustment allows us to index the segment directly,
  5744.         // instead of having to perform a subtraction for each reference.
  5745.         // See operator[] below.
  5746.         //
  5747.         assert(Blksize() <= pool -> Blksize()); // There must be enough room to allocate block
  5748.  
  5749.         base[k] = (T *) pool -> Alloc(sizeof(T) * Blksize());
  5750.         base[k] -= size;
  5751.  
  5752.         //
  5753.         // Finally, we update size.
  5754.         //
  5755.         size += Blksize();
  5756.  
  5757.         return;
  5758.     }
  5759.  
  5760.  
  5761. template <class T>
  5762.     //
  5763.     // Constructor of a ast array.
  5764.     //
  5765.     AstArray<T>::AstArray(StoragePool *pool_, unsigned estimate) : pool(pool_)
  5766.     {
  5767.         assert(sizeof(T) == sizeof(StoragePool::Cell)); // AstArray should only be used for arrays of pointers.
  5768.         assert(pool -> Blksize() >= 256); // There must be enough space in the storage pool to move !!!
  5769.  
  5770.         if (estimate == 0)
  5771.             log_blksize = 6; // take a guess
  5772.         else
  5773.         {
  5774.             for (log_blksize = 1; (((unsigned) 1 << log_blksize) < estimate) && (log_blksize < 31); log_blksize++)
  5775.                 ;
  5776.         }
  5777.  
  5778.         //
  5779.         // Increment a base_increment size that is big enough not to have to
  5780.         // be reallocated. Find a block size that is smaller that the block
  5781.         // size of the pool.
  5782.         //
  5783.         base_increment = (Blksize() > pool -> Blksize() ? Blksize() / pool -> Blksize() : 1) * 2;
  5784.         while (Blksize() >= pool -> Blksize())
  5785.             log_blksize--;
  5786.  
  5787.         base_size = 0;
  5788.         size = 0;
  5789.         top = 0;
  5790.         base = NULL;
  5791.     }
  5792.  
  5793.  
  5794. #endif
  5795.